OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
7 #include "content/browser/frame_host/cross_process_frame_connector.h" | 9 #include "content/browser/frame_host/cross_process_frame_connector.h" |
8 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
9 #include "content/browser/frame_host/render_frame_proxy_host.h" | 11 #include "content/browser/frame_host/render_frame_proxy_host.h" |
10 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 12 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
17 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
18 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
19 #include "content/public/test/content_browser_test.h" | |
20 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
23 #include "content/test/content_browser_test_utils_internal.h" | 24 #include "content/test/content_browser_test_utils_internal.h" |
24 #include "net/dns/mock_host_resolver.h" | 25 #include "net/dns/mock_host_resolver.h" |
25 #include "url/gurl.h" | |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 class SitePerProcessWebContentsObserver: public WebContentsObserver { | 29 class SitePerProcessWebContentsObserver: public WebContentsObserver { |
30 public: | 30 public: |
31 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) | 31 explicit SitePerProcessWebContentsObserver(WebContents* web_contents) |
32 : WebContentsObserver(web_contents), | 32 : WebContentsObserver(web_contents), |
33 navigation_succeeded_(false) {} | 33 navigation_succeeded_(false) {} |
34 virtual ~SitePerProcessWebContentsObserver() {} | 34 virtual ~SitePerProcessWebContentsObserver() {} |
35 | 35 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 details_ = details; | 142 details_ = details; |
143 seen_twice_ = seen_; | 143 seen_twice_ = seen_; |
144 seen_ = true; | 144 seen_ = true; |
145 if (!running_) | 145 if (!running_) |
146 return; | 146 return; |
147 | 147 |
148 message_loop_runner_->Quit(); | 148 message_loop_runner_->Quit(); |
149 running_ = false; | 149 running_ = false; |
150 } | 150 } |
151 | 151 |
152 class SitePerProcessBrowserTest : public ContentBrowserTest { | 152 // |
153 public: | 153 // SitePerProcessBrowserTest |
154 SitePerProcessBrowserTest() {} | 154 // |
155 | 155 |
156 protected: | 156 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
157 // Start at a data URL so each extra navigation creates a navigation entry. | 157 }; |
158 // (The first navigation will silently be classified as AUTO_SUBFRAME.) | 158 |
159 // TODO(creis): This won't be necessary when we can wait for LOAD_STOP. | 159 void SitePerProcessBrowserTest::StartFrameAtDataURL() { |
160 void StartFrameAtDataURL() { | 160 std::string data_url_script = |
161 std::string data_url_script = | |
162 "var iframes = document.getElementById('test');iframes.src=" | 161 "var iframes = document.getElementById('test');iframes.src=" |
163 "'data:text/html,dataurl';"; | 162 "'data:text/html,dataurl';"; |
164 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); | 163 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); |
165 } | 164 } |
166 | 165 |
167 bool NavigateIframeToURL(Shell* window, | 166 bool SitePerProcessBrowserTest::NavigateIframeToURL(Shell* window, |
168 const GURL& url, | 167 const GURL& url, |
169 std::string iframe_id) { | 168 std::string iframe_id) { |
170 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe | 169 // TODO(creis): This should wait for LOAD_STOP, but cross-site subframe |
171 // navigations generate extra DidStartLoading and DidStopLoading messages. | 170 // navigations generate extra DidStartLoading and DidStopLoading messages. |
172 // Until we replace swappedout:// with frame proxies, we need to listen for | 171 // Until we replace swappedout:// with frame proxies, we need to listen for |
173 // something else. For now, we trigger NEW_SUBFRAME navigations and listen | 172 // something else. For now, we trigger NEW_SUBFRAME navigations and listen |
174 // for commit. | 173 // for commit. |
175 std::string script = base::StringPrintf( | 174 std::string script = base::StringPrintf( |
176 "setTimeout(\"" | 175 "setTimeout(\"" |
177 "var iframes = document.getElementById('%s');iframes.src='%s';" | 176 "var iframes = document.getElementById('%s');iframes.src='%s';" |
178 "\",0)", | 177 "\",0)", |
179 iframe_id.c_str(), url.spec().c_str()); | 178 iframe_id.c_str(), url.spec().c_str()); |
180 WindowedNotificationObserver load_observer( | 179 WindowedNotificationObserver load_observer( |
181 NOTIFICATION_NAV_ENTRY_COMMITTED, | 180 NOTIFICATION_NAV_ENTRY_COMMITTED, |
182 Source<NavigationController>( | 181 Source<NavigationController>( |
183 &window->web_contents()->GetController())); | 182 &window->web_contents()->GetController())); |
184 bool result = ExecuteScript(window->web_contents(), script); | 183 bool result = ExecuteScript(window->web_contents(), script); |
185 load_observer.Wait(); | 184 load_observer.Wait(); |
186 return result; | 185 return result; |
187 } | 186 } |
188 | 187 |
189 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 188 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
190 command_line->AppendSwitch(switches::kSitePerProcess); | 189 command_line->AppendSwitch(switches::kSitePerProcess); |
191 } | |
192 }; | 190 }; |
193 | 191 |
194 // Ensure that we can complete a cross-process subframe navigation. | 192 // Ensure that we can complete a cross-process subframe navigation. |
195 // Crashes ChromeOS bot, but the bug is probably present on other platforms | 193 // Crashes ChromeOS bot, but the bug is probably present on other platforms |
196 // also. http://crbug.com/399775 | 194 // also. http://crbug.com/399775 |
197 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) { | 195 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrossSiteIframe) { |
198 host_resolver()->AddRule("*", "127.0.0.1"); | 196 host_resolver()->AddRule("*", "127.0.0.1"); |
199 ASSERT_TRUE(test_server()->Start()); | 197 ASSERT_TRUE(test_server()->Start()); |
200 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | 198 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
201 NavigateToURL(shell(), main_url); | 199 NavigateToURL(shell(), main_url); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 "server-redirect?" + client_redirect_http_url.spec())); | 558 "server-redirect?" + client_redirect_http_url.spec())); |
561 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); | 559 EXPECT_TRUE(NavigateIframeToURL(shell(), server_redirect_http_url, "test")); |
562 | 560 |
563 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 561 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
564 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); | 562 EXPECT_EQ(observer.navigation_url(), client_redirect_http_url); |
565 EXPECT_FALSE(observer.navigation_succeeded()); | 563 EXPECT_FALSE(observer.navigation_succeeded()); |
566 } | 564 } |
567 } | 565 } |
568 | 566 |
569 } // namespace content | 567 } // namespace content |
OLD | NEW |