Advertisement
Guest User

Test case for bug 2940926

a guest
Nov 24th, 2010
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. // put these three files in the default package together
  2. // IFrameTests.java
  3.  
  4. import static org.junit.Assert.assertEquals;
  5. import static org.junit.Assert.assertNotNull;
  6.  
  7. import java.net.URL;
  8.  
  9. import org.junit.Test;
  10.  
  11. import com.gargoylesoftware.htmlunit.BrowserVersion;
  12. import com.gargoylesoftware.htmlunit.WebClient;
  13. import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
  14. import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame;
  15. import com.gargoylesoftware.htmlunit.html.HtmlPage;
  16. import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
  17.  
  18. public class IFrameTests {
  19.    
  20.     @Test
  21.     public void testIFrameCreatedWithInnerHTML() throws Exception {
  22.         WebClient client = new WebClient(BrowserVersion.FIREFOX_3);
  23.         URL url = getClass().getResource("container.html");
  24.         assertNotNull(url);
  25.         HtmlPage page = client.getPage(url);
  26.         HtmlAnchor theLink = (HtmlAnchor) page.getElementById("theLink");
  27.         theLink.click();
  28.         int remaining = page.getEnclosingWindow().getJobManager().waitForJobsStartingBefore(100);
  29.         assertEquals(0, remaining);
  30.         HtmlInlineFrame theIFrame = (HtmlInlineFrame) page.getElementById("theIFrame");
  31.         HtmlPage enclosedPage = (HtmlPage) theIFrame.getEnclosedPage();
  32.         HtmlParagraph theParagraph = (HtmlParagraph) enclosedPage.getElementById("theParagraph");
  33.         assertNotNull(theParagraph);
  34.         assertEquals("Hello, world!", theParagraph.getTextContent());
  35.     }
  36.    
  37. }
  38.  
  39. /* container.html
  40.  
  41. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  42. <html>
  43. <head>
  44. <title>Container</title>
  45. <script type="text/javascript">
  46. function main() {
  47.     var receptacle = document.getElementById('receptacle');
  48.     receptacle.innerHTML = '<iframe id="theIFrame" src="content.html"></iframe>';
  49. }
  50. </script>
  51. </head>
  52. <body>
  53.  
  54. <div id="receptacle"></div>
  55.  
  56. <p><a id="theLink" href="javascript:main();">Click Me</a></p>
  57.  
  58. </body>
  59. </html>
  60.  
  61. */
  62.  
  63. /* content.html
  64.  
  65. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  66. <html>
  67. <head>
  68. <title>Content</title>
  69. </head>
  70. <body>
  71.  
  72. <p id="theParagraph">Hello, world!</p>
  73.  
  74. </body>
  75. </html>
  76.  
  77. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement