1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.net.URL; 41 42 import com.gargoylesoftware.htmlunit.MockWebConnection; 43 import com.gargoylesoftware.htmlunit.WebClient; 44 import com.gargoylesoftware.htmlunit.WebTestCase; 45 import com.gargoylesoftware.htmlunit.WebWindow; 46 47 55 public class HtmlFrameSetTest extends WebTestCase { 56 57 62 public HtmlFrameSetTest( final String name ) { 63 super( name ); 64 } 65 66 67 70 public void testLoadingFrameSet() 71 throws Exception { 72 73 final String firstContent 74 = "<html><head><title>First</title></head>" 75 + "<frameset cols='130,*'>" 76 + " <frame scrolling='no' name='left' SRC='http://second' frameborder='1' />" 77 + " <frame scrolling='auto' name='right' SRC='http://third' frameborder='1' />" 78 + " <noframes>" 79 + " <body>Frames not supported</body>" 80 + " </noframes>" 81 + "</frameset>" 82 + "</html>"; 83 final String secondContent = "<html><head><title>Second</title></head><body></body></html>"; 84 final String thirdContent = "<html><head><title>Third</title></head><body></body></html>"; 85 86 final WebClient webClient = new WebClient(); 87 88 final MockWebConnection webConnection = new MockWebConnection( webClient ); 89 webConnection.setResponse(URL_FIRST, firstContent); 90 webConnection.setResponse(URL_SECOND, secondContent); 91 webConnection.setResponse(URL_THIRD, thirdContent); 92 93 webClient.setWebConnection( webConnection ); 94 95 final HtmlPage firstPage = (HtmlPage) webClient.getPage(URL_FIRST); 96 assertEquals( "First", firstPage.getTitleText() ); 97 98 final WebWindow secondWebWindow = webClient.getWebWindowByName("left"); 99 assertSame( firstPage, ((BaseFrame.FrameWindow) secondWebWindow).getEnclosingPage() ); 100 assertEquals( "Second", ((HtmlPage) secondWebWindow.getEnclosedPage()).getTitleText() ); 101 102 final WebWindow thirdWebWindow = webClient.getWebWindowByName("right"); 103 assertInstanceOf( thirdWebWindow, BaseFrame.FrameWindow.class ); 104 assertSame( firstPage, ((BaseFrame.FrameWindow) thirdWebWindow).getEnclosingPage() ); 105 assertEquals( "Third", ((HtmlPage)thirdWebWindow.getEnclosedPage()).getTitleText() ); 106 } 107 108 109 112 public void testLoadingIFrames() 113 throws Exception { 114 115 final String firstContent 116 = "<html><head><title>First</title></head>" 117 + "<body>" 118 + " <iframe name='left' SRC='http://second' />" 119 + " some stuff" 120 + "</html>"; 121 final String secondContent = "<html><head><title>Second</title></head><body></body></html>"; 122 123 final WebClient webClient = new WebClient(); 124 125 final MockWebConnection webConnection = new MockWebConnection( webClient ); 126 webConnection.setResponse(URL_FIRST, firstContent); 127 webConnection.setResponse(URL_SECOND, secondContent); 128 129 webClient.setWebConnection( webConnection ); 130 131 final HtmlPage firstPage = (HtmlPage) webClient.getPage(URL_FIRST); 132 assertEquals( "First", firstPage.getTitleText() ); 133 134 final WebWindow secondWebWindow = webClient.getWebWindowByName("left"); 135 assertInstanceOf(secondWebWindow, BaseFrame.FrameWindow.class); 136 assertSame( firstPage, ((BaseFrame.FrameWindow) secondWebWindow).getEnclosingPage() ); 137 assertEquals( "Second", ((HtmlPage)secondWebWindow.getEnclosedPage()).getTitleText() ); 138 } 139 140 146 public void testLoadingFrameSetWithRelativePaths() 147 throws Exception { 148 149 final String framesContent 150 = "<html><head><title>Frames</title></head>" 151 + "<frameset rows='110,*'>" 152 + " <frame SRC='subdir1/menu.html' name='menu' scrolling='no' border='0' noresize>" 153 + " <frame SRC='subdir2/first.html' name='test' border='0' auto>" 154 + "</frameset>" 155 + "<noframes>" 156 + " <body>Frames not supported</body>" 157 + "</noframes>" 158 + "</html>"; 159 final String menuContent 160 = "<html><head><title>Menu</title></head>" 161 + "<body>" 162 + " <script language='javascript'>" 163 + " function changeEditPage() {parent.test.location='../second.html';}" 164 + " </script>" 165 + " <a name ='changePage' onClick='javascript:changeEditPage();' HREF='#'>Click</a>." 166 + "</body>" 167 + "</html>"; 168 final String firstContent 169 = "<html><head><title>First</title></head>" 170 + "<body>First/body>" 171 + "</html>"; 172 final String secondContent 173 = "<html><head><title>Second</title></head>" 174 + "<body>Second</body>" 175 + "</html>"; 176 final String baseUrl = "http://framestest"; 177 178 final URL framesURL = new URL(baseUrl + "/frames.html"); 179 final URL menuURL = new URL(baseUrl + "/subdir1/menu.html"); 180 final URL firstURL = new URL(baseUrl + "/subdir2/first.html"); 181 final URL secondURL = new URL(baseUrl + "/second.html"); 182 183 final WebClient webClient = new WebClient(); 184 185 final MockWebConnection webConnection = new MockWebConnection( webClient ); 186 webConnection.setResponse(framesURL, framesContent); 187 webConnection.setResponse(menuURL, menuContent); 188 webConnection.setResponse(firstURL, firstContent); 189 webConnection.setResponse(secondURL, secondContent); 190 191 webClient.setWebConnection( webConnection ); 192 193 final HtmlPage framesPage = (HtmlPage) webClient.getPage(framesURL); 194 assertEquals( "Frames", framesPage.getTitleText() ); 195 196 final WebWindow menuWebWindow = webClient.getWebWindowByName("menu"); 197 final HtmlPage menuPage = (HtmlPage) menuWebWindow.getEnclosedPage(); 198 assertEquals( "Menu", menuPage.getTitleText() ); 199 200 final WebWindow testWebWindow = webClient.getWebWindowByName("test"); 201 assertEquals( "First", ((HtmlPage) testWebWindow.getEnclosedPage()).getTitleText() ); 202 203 final HtmlAnchor changePage = menuPage.getAnchorByName("changePage"); 204 changePage.click(); 205 assertEquals( "Second", ((HtmlPage) testWebWindow.getEnclosedPage()).getTitleText() ); 206 207 } 208 209 } 210 | Popular Tags |