Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 102433010: prerender: Add NavigationOrSwapObserver in browsertest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <deque> 5 #include <deque>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
37 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 37 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
38 #include "chrome/browser/task_manager/task_manager.h" 38 #include "chrome/browser/task_manager/task_manager.h"
39 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" 39 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
40 #include "chrome/browser/ui/browser.h" 40 #include "chrome/browser/ui/browser.h"
41 #include "chrome/browser/ui/browser_commands.h" 41 #include "chrome/browser/ui/browser_commands.h"
42 #include "chrome/browser/ui/browser_finder.h" 42 #include "chrome/browser/ui/browser_finder.h"
43 #include "chrome/browser/ui/browser_navigator.h" 43 #include "chrome/browser/ui/browser_navigator.h"
44 #include "chrome/browser/ui/browser_window.h" 44 #include "chrome/browser/ui/browser_window.h"
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" 45 #include "chrome/browser/ui/tabs/tab_strip_model.h"
46 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
46 #include "chrome/common/chrome_paths.h" 47 #include "chrome/common/chrome_paths.h"
47 #include "chrome/common/chrome_switches.h" 48 #include "chrome/common/chrome_switches.h"
48 #include "chrome/common/extensions/extension_constants.h" 49 #include "chrome/common/extensions/extension_constants.h"
49 #include "chrome/common/pref_names.h" 50 #include "chrome/common/pref_names.h"
50 #include "chrome/test/base/in_process_browser_test.h" 51 #include "chrome/test/base/in_process_browser_test.h"
51 #include "chrome/test/base/test_switches.h" 52 #include "chrome/test/base/test_switches.h"
52 #include "chrome/test/base/ui_test_utils.h" 53 #include "chrome/test/base/ui_test_utils.h"
53 #include "content/public/browser/browser_message_filter.h" 54 #include "content/public/browser/browser_message_filter.h"
54 #include "content/public/browser/devtools_agent_host.h" 55 #include "content/public/browser/devtools_agent_host.h"
55 #include "content/public/browser/devtools_client_host.h" 56 #include "content/public/browser/devtools_client_host.h"
56 #include "content/public/browser/devtools_manager.h" 57 #include "content/public/browser/devtools_manager.h"
57 #include "content/public/browser/navigation_controller.h" 58 #include "content/public/browser/navigation_controller.h"
58 #include "content/public/browser/navigation_entry.h" 59 #include "content/public/browser/navigation_entry.h"
59 #include "content/public/browser/notification_service.h" 60 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/render_process_host.h" 61 #include "content/public/browser/render_process_host.h"
61 #include "content/public/browser/render_view_host.h" 62 #include "content/public/browser/render_view_host.h"
62 #include "content/public/browser/site_instance.h" 63 #include "content/public/browser/site_instance.h"
63 #include "content/public/browser/web_contents.h" 64 #include "content/public/browser/web_contents.h"
65 #include "content/public/browser/web_contents_observer.h"
64 #include "content/public/common/url_constants.h" 66 #include "content/public/common/url_constants.h"
65 #include "content/public/test/browser_test_utils.h" 67 #include "content/public/test/browser_test_utils.h"
66 #include "content/public/test/test_navigation_observer.h" 68 #include "content/public/test/test_navigation_observer.h"
67 #include "content/public/test/test_utils.h" 69 #include "content/public/test/test_utils.h"
68 #include "content/test/net/url_request_mock_http_job.h" 70 #include "content/test/net/url_request_mock_http_job.h"
69 #include "extensions/common/switches.h" 71 #include "extensions/common/switches.h"
70 #include "grit/generated_resources.h" 72 #include "grit/generated_resources.h"
71 #include "net/base/escape.h" 73 #include "net/base/escape.h"
72 #include "net/dns/mock_host_resolver.h" 74 #include "net/dns/mock_host_resolver.h"
73 #include "net/url_request/url_request_context.h" 75 #include "net/url_request/url_request_context.h"
74 #include "net/url_request/url_request_context_getter.h" 76 #include "net/url_request/url_request_context_getter.h"
75 #include "net/url_request/url_request_filter.h" 77 #include "net/url_request/url_request_filter.h"
76 #include "net/url_request/url_request_job.h" 78 #include "net/url_request/url_request_job.h"
77 #include "ui/base/l10n/l10n_util.h" 79 #include "ui/base/l10n/l10n_util.h"
78 #include "url/gurl.h" 80 #include "url/gurl.h"
79 81
80 using content::BrowserThread; 82 using content::BrowserThread;
81 using content::DevToolsAgentHost; 83 using content::DevToolsAgentHost;
82 using content::DevToolsClientHost; 84 using content::DevToolsClientHost;
83 using content::DevToolsManager; 85 using content::DevToolsManager;
84 using content::NavigationController; 86 using content::NavigationController;
85 using content::OpenURLParams; 87 using content::OpenURLParams;
86 using content::Referrer; 88 using content::Referrer;
87 using content::RenderViewHost; 89 using content::RenderViewHost;
88 using content::RenderWidgetHost; 90 using content::RenderWidgetHost;
89 using content::WebContents; 91 using content::WebContents;
92 using content::WebContentsObserver;
90 93
91 // Prerender tests work as follows: 94 // Prerender tests work as follows:
92 // 95 //
93 // A page with a prefetch link to the test page is loaded. Once prerendered, 96 // A page with a prefetch link to the test page is loaded. Once prerendered,
94 // its Javascript function DidPrerenderPass() is called, which returns true if 97 // its Javascript function DidPrerenderPass() is called, which returns true if
95 // the page behaves as expected when prerendered. 98 // the page behaves as expected when prerendered.
96 // 99 //
97 // The prerendered page is then displayed on a tab. The Javascript function 100 // The prerendered page is then displayed on a tab. The Javascript function
98 // DidDisplayPass() is called, and returns true if the page behaved as it 101 // DidDisplayPass() is called, and returns true if the page behaved as it
99 // should while being displayed. 102 // should while being displayed.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 channel_destroyed_ = true; 205 channel_destroyed_ = true;
203 run_loop_.Quit(); 206 run_loop_.Quit();
204 } 207 }
205 208
206 bool channel_destroyed_; 209 bool channel_destroyed_;
207 base::RunLoop run_loop_; 210 base::RunLoop run_loop_;
208 211
209 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher); 212 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher);
210 }; 213 };
211 214
215 // A simple observer to wait on either a load or a swap of a WebContents.
216 class NavigationOrSwapObserver : public WebContentsObserver,
217 public TabStripModelObserver {
218 public:
219 // Waits for either a load or a swap of |tab_strip_model|'s active
220 // WebContents.
221 explicit NavigationOrSwapObserver(TabStripModel* tab_strip_model)
222 : WebContentsObserver(tab_strip_model->GetActiveWebContents()),
223 tab_strip_model_(tab_strip_model) {
224 tab_strip_model_->AddObserver(this);
225 }
226
227 ~NavigationOrSwapObserver() {
228 tab_strip_model_->RemoveObserver(this);
229 }
230
231 void Wait() {
232 loop_.Run();
233 }
234
235 // WebContentsObserver implementation:
236 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE {
237 loop_.Quit();
238 }
239
240 // TabStripModelObserver implementation:
241 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
242 WebContents* old_contents,
243 WebContents* new_contents,
244 int index) OVERRIDE {
245 if (old_contents != web_contents())
mmenke 2014/01/07 15:09:17 Does this ever happen? If not, could use an EXPEC
davidben 2014/01/07 17:31:34 Hrm. Doesn't currently happen, but I was thinking
mmenke 2014/01/07 17:44:50 NavigateToDestURLInNewTab()? There used to be a t
davidben 2014/01/07 18:57:14 Well, NavigateToDestURLInNewTab creates a new tab
246 return;
247 loop_.Quit();
248 }
249
250 private:
251 TabStripModel* tab_strip_model_;
252 base::RunLoop loop_;
253 };
254
212 // PrerenderContents that stops the UI message loop on DidStopLoading(). 255 // PrerenderContents that stops the UI message loop on DidStopLoading().
213 class TestPrerenderContents : public PrerenderContents { 256 class TestPrerenderContents : public PrerenderContents {
214 public: 257 public:
215 TestPrerenderContents( 258 TestPrerenderContents(
216 PrerenderManager* prerender_manager, 259 PrerenderManager* prerender_manager,
217 Profile* profile, 260 Profile* profile,
218 const GURL& url, 261 const GURL& url,
219 const content::Referrer& referrer, 262 const content::Referrer& referrer,
220 Origin origin, 263 Origin origin,
221 int expected_number_of_loads, 264 int expected_number_of_loads,
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 public: 641 public:
599 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) { 642 RestorePrerenderMode() : prev_mode_(PrerenderManager::GetMode()) {
600 } 643 }
601 644
602 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); } 645 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); }
603 private: 646 private:
604 PrerenderManager::PrerenderManagerMode prev_mode_; 647 PrerenderManager::PrerenderManagerMode prev_mode_;
605 }; 648 };
606 649
607 // URLRequestJob (and associated handler) which never starts. 650 // URLRequestJob (and associated handler) which never starts.
608 class NeverStartURLRequestJob : public net::URLRequestJob { 651 class NeverStartURLRequestJob : public net::URLRequestJob {
mmenke 2014/01/07 15:09:17 While you're here, could you rename this? Maybe N
davidben 2014/01/07 17:31:34 Done.
609 public: 652 public:
610 NeverStartURLRequestJob(net::URLRequest* request, 653 NeverStartURLRequestJob(net::URLRequest* request,
611 net::NetworkDelegate* network_delegate) 654 net::NetworkDelegate* network_delegate)
612 : net::URLRequestJob(request, network_delegate) { 655 : net::URLRequestJob(request, network_delegate) {
613 } 656 }
614 657
615 virtual void Start() OVERRIDE {} 658 virtual void Start() OVERRIDE {}
616 659
617 private: 660 private:
618 virtual ~NeverStartURLRequestJob() {} 661 virtual ~NeverStartURLRequestJob() {}
619 }; 662 };
620 663
621 class NeverStartProtocolHandler 664 class NeverStartProtocolHandler
622 : public net::URLRequestJobFactory::ProtocolHandler { 665 : public net::URLRequestJobFactory::ProtocolHandler {
623 public: 666 public:
624 NeverStartProtocolHandler() {} 667 explicit NeverStartProtocolHandler(const base::FilePath& file)
668 : file_(file),
669 first_run_(true) {
670 }
625 virtual ~NeverStartProtocolHandler() {} 671 virtual ~NeverStartProtocolHandler() {}
626 672
627 virtual net::URLRequestJob* MaybeCreateJob( 673 virtual net::URLRequestJob* MaybeCreateJob(
628 net::URLRequest* request, 674 net::URLRequest* request,
629 net::NetworkDelegate* network_delegate) const OVERRIDE { 675 net::NetworkDelegate* network_delegate) const OVERRIDE {
630 return new NeverStartURLRequestJob(request, network_delegate); 676 if (first_run_) {
mmenke 2014/01/07 15:09:17 While this isn't the most complicated class, this
davidben 2014/01/07 17:31:34 Done.
677 first_run_ = false;
678 return new NeverStartURLRequestJob(request, network_delegate);
679 }
680 return new content::URLRequestMockHTTPJob(request, network_delegate, file_);
631 } 681 }
682 private:
mmenke 2014/01/07 15:09:17 nit: Blank line before private.
davidben 2014/01/07 17:31:34 Done.
683 base::FilePath file_;
684 mutable bool first_run_;
632 }; 685 };
633 686
634 void CreateNeverStartProtocolHandlerOnIO(const GURL& url) { 687 // Makes |url| never respond on the first load, and then with the contents of
688 // |file| afterwards.
689 void CreateNeverStartProtocolHandlerOnIO(const GURL& url,
690 const base::FilePath& file) {
635 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 691 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
636 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> never_respond_handler( 692 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> never_respond_handler(
637 new NeverStartProtocolHandler()); 693 new NeverStartProtocolHandler(file));
638 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 694 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler(
639 url, never_respond_handler.Pass()); 695 url, never_respond_handler.Pass());
640 } 696 }
641 697
642 // Makes |url| respond to requests with the contents of |file|. 698 // Makes |url| respond to requests with the contents of |file|.
643 void CreateMockProtocolHandlerOnIO(const GURL& url, 699 void CreateMockProtocolHandlerOnIO(const GURL& url,
644 const base::FilePath& file) { 700 const base::FilePath& file) {
645 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 701 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
646 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler( 702 net::URLRequestFilter::GetInstance()->AddUrlProtocolHandler(
647 url, content::URLRequestMockHTTPJob::CreateProtocolHandlerForSingleFile( 703 url, content::URLRequestMockHTTPJob::CreateProtocolHandlerForSingleFile(
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 void NavigateToDestURLInNewTab() const { 887 void NavigateToDestURLInNewTab() const {
832 // First, open a new tab. 888 // First, open a new tab.
833 ui_test_utils::NavigateToURLWithDisposition( 889 ui_test_utils::NavigateToURLWithDisposition(
834 current_browser(), GURL(content::kAboutBlankURL), 890 current_browser(), GURL(content::kAboutBlankURL),
835 NEW_FOREGROUND_TAB, 891 NEW_FOREGROUND_TAB,
836 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 892 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
837 // Next, navigate to the destination URL. The swap-in will not succeed, 893 // Next, navigate to the destination URL. The swap-in will not succeed,
838 // due to session storage namespace mismatch. The merge is only kicked off 894 // due to session storage namespace mismatch. The merge is only kicked off
839 // asynchronously. 895 // asynchronously.
840 NavigateToDestURLWithDisposition(CURRENT_TAB, false); 896 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
841 // Run the message loop, waiting for the merge to complete, the swapin to
842 // be reattempted, and to eventually succeed.
843 content::RunMessageLoop();
844 } 897 }
845 898
846 // Opens the url in a new tab, with no opener. 899 // Opens the url in a new tab, with no opener.
847 void NavigateToDestURLWithDisposition( 900 void NavigateToDestURLWithDisposition(
848 WindowOpenDisposition disposition, 901 WindowOpenDisposition disposition,
849 bool expect_swap_to_succeed) const { 902 bool expect_swap_to_succeed) const {
850 NavigateToURLWithParams( 903 NavigateToURLWithParams(
851 content::OpenURLParams(dest_url_, Referrer(), disposition, 904 content::OpenURLParams(dest_url_, Referrer(), disposition,
852 content::PAGE_TRANSITION_TYPED, false), 905 content::PAGE_TRANSITION_TYPED, false),
853 expect_swap_to_succeed); 906 expect_swap_to_succeed);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 } 1198 }
1146 1199
1147 void IncreasePrerenderMemory() { 1200 void IncreasePrerenderMemory() {
1148 // Increase the memory allowed in a prerendered page above normal settings. 1201 // Increase the memory allowed in a prerendered page above normal settings.
1149 // Debug build bots occasionally run against the default limit, and tests 1202 // Debug build bots occasionally run against the default limit, and tests
1150 // were failing because the prerender was canceled due to memory exhaustion. 1203 // were failing because the prerender was canceled due to memory exhaustion.
1151 // http://crbug.com/93076 1204 // http://crbug.com/93076
1152 GetPrerenderManager()->mutable_config().max_bytes = 1000 * 1024 * 1024; 1205 GetPrerenderManager()->mutable_config().max_bytes = 1000 * 1024 * 1024;
1153 } 1206 }
1154 1207
1208 bool DidPrerenderPass(WebContents* web_contents) const {
1209 bool prerender_test_result = false;
1210 CHECK(content::ExecuteScriptAndExtractBool(
1211 web_contents,
1212 "window.domAutomationController.send(DidPrerenderPass())",
1213 &prerender_test_result));
1214 return prerender_test_result;
1215 }
1216
1217 bool DidDisplayPass(WebContents* web_contents) const {
1218 bool display_test_result = false;
1219 CHECK(content::ExecuteScriptAndExtractBool(
1220 web_contents,
1221 "window.domAutomationController.send(DidDisplayPass())",
1222 &display_test_result));
mmenke 2014/01/07 15:09:17 Do we need these CHECKs? Seems like we can just r
davidben 2014/01/07 17:31:34 Done. I think it's worthwhile to be able to distin
mmenke 2014/01/07 17:44:50 You could return a testing::AssertionResult, with
1223 return display_test_result;
1224 }
1225
1155 protected: 1226 protected:
1156 bool autostart_test_server_; 1227 bool autostart_test_server_;
1157 1228
1158 private: 1229 private:
1159 void PrerenderTestURLImpl( 1230 void PrerenderTestURLImpl(
1160 const GURL& prerender_url, 1231 const GURL& prerender_url,
1161 const GURL& destination_url, 1232 const GURL& destination_url,
1162 const std::deque<FinalStatus>& expected_final_status_queue, 1233 const std::deque<FinalStatus>& expected_final_status_queue,
1163 int expected_number_of_loads, 1234 int expected_number_of_loads,
1164 bool prerender_should_wait_for_ready_title) { 1235 bool prerender_should_wait_for_ready_title) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { 1302 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) {
1232 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents); 1303 ASSERT_NE(static_cast<PrerenderContents*>(NULL), prerender_contents);
1233 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); 1304 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status());
1234 1305
1235 if (call_javascript_) { 1306 if (call_javascript_) {
1236 // Wait for the prerendered page to change title to signal it is ready 1307 // Wait for the prerendered page to change title to signal it is ready
1237 // if required. 1308 // if required.
1238 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); 1309 prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired();
1239 1310
1240 // Check if page behaves as expected while in prerendered state. 1311 // Check if page behaves as expected while in prerendered state.
1241 bool prerender_test_result = false; 1312 EXPECT_TRUE(DidPrerenderPass(prerender_contents->prerender_contents()));
1242 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1243 prerender_contents->GetRenderViewHostMutable(),
1244 "window.domAutomationController.send(DidPrerenderPass())",
1245 &prerender_test_result));
1246 EXPECT_TRUE(prerender_test_result);
1247 } 1313 }
1248 1314
1249 // Test that the referring page received events. 1315 // Test that the referring page received events.
1250 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); 1316 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
1251 if (check_load_events_) { 1317 if (check_load_events_) {
1252 EXPECT_EQ(expected_number_of_loads, 1318 EXPECT_EQ(expected_number_of_loads,
1253 GetPrerenderLoadEventCountForLinkNumber(0)); 1319 GetPrerenderLoadEventCountForLinkNumber(0));
1254 } 1320 }
1255 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0)); 1321 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
1256 } else { 1322 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 page_load_observer.reset( 1363 page_load_observer.reset(
1298 new content::WindowedNotificationObserver( 1364 new content::WindowedNotificationObserver(
1299 content::NOTIFICATION_LOAD_STOP, 1365 content::NOTIFICATION_LOAD_STOP,
1300 content::Source<NavigationController>( 1366 content::Source<NavigationController>(
1301 &web_contents->GetController()))); 1367 &web_contents->GetController())));
1302 } 1368 }
1303 } 1369 }
1304 1370
1305 // Navigate to the prerendered URL, but don't run the message loop. Browser 1371 // Navigate to the prerendered URL, but don't run the message loop. Browser
1306 // issued navigations to prerendered pages will synchronously swap in the 1372 // issued navigations to prerendered pages will synchronously swap in the
1307 // prerendered page. 1373 // prerendered page.
mmenke 2014/01/07 15:09:17 This comment is no longer correct.
davidben 2014/01/07 17:31:34 Done.
1374 NavigationOrSwapObserver swap_observer(
1375 current_browser()->tab_strip_model());
1308 WebContents* target_web_contents = current_browser()->OpenURL(params); 1376 WebContents* target_web_contents = current_browser()->OpenURL(params);
1377 swap_observer.Wait();
1309 1378
1310 if (web_contents && expect_swap_to_succeed) { 1379 if (web_contents && expect_swap_to_succeed) {
1311 EXPECT_EQ(web_contents, target_web_contents); 1380 EXPECT_EQ(web_contents, target_web_contents);
1312 if (call_javascript_) { 1381 if (call_javascript_) {
1313 if (page_load_observer.get()) 1382 if (page_load_observer.get())
1314 page_load_observer->Wait(); 1383 page_load_observer->Wait();
1315 1384
1316 bool display_test_result = false; 1385 EXPECT_TRUE(DidDisplayPass(web_contents));
1317 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1318 web_contents,
1319 "window.domAutomationController.send(DidDisplayPass())",
1320 &display_test_result));
1321 EXPECT_TRUE(display_test_result);
1322 } 1386 }
1323 } 1387 }
1324 } 1388 }
1325 1389
1326 // Opens the prerendered page using javascript functions in the 1390 // Opens the prerendered page using javascript functions in the
1327 // loader page. |javascript_function_name| should be a 0 argument function 1391 // loader page. |javascript_function_name| should be a 0 argument function
1328 // which is invoked. 1392 // which is invoked.
1329 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) 1393 void OpenDestURLWithJSImpl(const std::string& javascript_function_name)
1330 const { 1394 const {
1331 TestPrerenderContents* prerender_contents = GetPrerenderContents(); 1395 TestPrerenderContents* prerender_contents = GetPrerenderContents();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 FINAL_STATUS_USED, 1609 FINAL_STATUS_USED,
1546 1); 1610 1);
1547 NavigateToDestURL(); 1611 NavigateToDestURL();
1548 } 1612 }
1549 1613
1550 // Checks that the prerendering of a page is canceled correctly if we try to 1614 // Checks that the prerendering of a page is canceled correctly if we try to
1551 // swap it in before it commits. 1615 // swap it in before it commits.
1552 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) { 1616 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) {
1553 // Navigate to a page that triggers a prerender for a URL that never commits. 1617 // Navigate to a page that triggers a prerender for a URL that never commits.
1554 const GURL kNoCommitUrl("http://never-respond.example.com"); 1618 const GURL kNoCommitUrl("http://never-respond.example.com");
1619 base::FilePath file(FILE_PATH_LITERAL(
1620 "chrome/test/data/prerender/prerender_page.html"));
1555 BrowserThread::PostTask( 1621 BrowserThread::PostTask(
1556 BrowserThread::IO, FROM_HERE, 1622 BrowserThread::IO, FROM_HERE,
1557 base::Bind(&CreateNeverStartProtocolHandlerOnIO, kNoCommitUrl)); 1623 base::Bind(&CreateNeverStartProtocolHandlerOnIO, kNoCommitUrl, file));
1558 DisableJavascriptCalls(); 1624 DisableJavascriptCalls();
1559 PrerenderTestURL(kNoCommitUrl, 1625 PrerenderTestURL(kNoCommitUrl,
1560 FINAL_STATUS_NAVIGATION_UNCOMMITTED, 1626 FINAL_STATUS_NAVIGATION_UNCOMMITTED,
1561 0); 1627 0);
1562 1628
1563 // Navigate to the URL, but assume the contents won't be swapped in. 1629 // Navigate to the URL, but assume the contents won't be swapped in.
1564 NavigateToDestURLWithDisposition(CURRENT_TAB, false); 1630 NavigateToDestURLWithDisposition(CURRENT_TAB, false);
1565 } 1631 }
1566 1632
1567 // Checks that client redirects don't add alias URLs until after they commit. 1633 // Checks that client redirects don't add alias URLs until after they commit.
1568 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap2) { 1634 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap2) {
1569 // Navigate to a page that then navigates to a URL that never commits. 1635 // Navigate to a page that then navigates to a URL that never commits.
1570 const GURL kNoCommitUrl("http://never-respond.example.com"); 1636 const GURL kNoCommitUrl("http://never-respond.example.com");
1637 base::FilePath file(FILE_PATH_LITERAL(
1638 "chrome/test/data/prerender/prerender_page.html"));
1571 BrowserThread::PostTask( 1639 BrowserThread::PostTask(
1572 BrowserThread::IO, FROM_HERE, 1640 BrowserThread::IO, FROM_HERE,
1573 base::Bind(&CreateNeverStartProtocolHandlerOnIO, kNoCommitUrl)); 1641 base::Bind(&CreateNeverStartProtocolHandlerOnIO, kNoCommitUrl, file));
1574 DisableJavascriptCalls(); 1642 DisableJavascriptCalls();
1575 PrerenderTestURL(CreateClientRedirect(kNoCommitUrl.spec()), 1643 PrerenderTestURL(CreateClientRedirect(kNoCommitUrl.spec()),
1576 FINAL_STATUS_APP_TERMINATING, 1); 1644 FINAL_STATUS_APP_TERMINATING, 1);
1577 1645
1578 // Navigating to the second URL should not swap. 1646 // Navigating to the second URL should not swap.
1579 NavigateToURLWithDisposition(kNoCommitUrl, CURRENT_TAB, false); 1647 NavigateToURLWithDisposition(kNoCommitUrl, CURRENT_TAB, false);
1580 } 1648 }
1581 1649
1582 // Checks that the prerendering of a page is canceled correctly when a 1650 // Checks that the prerendering of a page is canceled correctly when a
1583 // Javascript alert is called. 1651 // Javascript alert is called.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 1713
1646 // Run this check again. When we try to load aa ppapi plugin, the 1714 // Run this check again. When we try to load aa ppapi plugin, the
1647 // "loadstart" event is asynchronously posted to a message loop. 1715 // "loadstart" event is asynchronously posted to a message loop.
1648 // It's possible that earlier call could have been run before the 1716 // It's possible that earlier call could have been run before the
1649 // the "loadstart" event was posted. 1717 // the "loadstart" event was posted.
1650 // TODO(mmenke): While this should reliably fail on regressions, the 1718 // TODO(mmenke): While this should reliably fail on regressions, the
1651 // reliability depends on the specifics of ppapi plugin 1719 // reliability depends on the specifics of ppapi plugin
1652 // loading. It would be great if we could avoid that. 1720 // loading. It would be great if we could avoid that.
1653 WebContents* web_contents = 1721 WebContents* web_contents =
1654 browser()->tab_strip_model()->GetActiveWebContents(); 1722 browser()->tab_strip_model()->GetActiveWebContents();
1655 bool display_test_result = false; 1723 EXPECT_TRUE(DidDisplayPass(web_contents));
1656 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1657 web_contents,
1658 "window.domAutomationController.send(DidDisplayPass())",
1659 &display_test_result));
1660 EXPECT_TRUE(display_test_result);
1661 } 1724 }
1662 1725
1663 // Checks that plugins in an iframe are not loaded while a page is 1726 // Checks that plugins in an iframe are not loaded while a page is
1664 // being preloaded, but are loaded when the page is displayed. 1727 // being preloaded, but are loaded when the page is displayed.
1665 #if defined(USE_AURA) && !defined(OS_WIN) 1728 #if defined(USE_AURA) && !defined(OS_WIN)
1666 // http://crbug.com/103496 1729 // http://crbug.com/103496
1667 #define MAYBE_PrerenderIframeDelayLoadPlugin \ 1730 #define MAYBE_PrerenderIframeDelayLoadPlugin \
1668 DISABLED_PrerenderIframeDelayLoadPlugin 1731 DISABLED_PrerenderIframeDelayLoadPlugin
1669 #elif defined(OS_MACOSX) 1732 #elif defined(OS_MACOSX)
1670 // http://crbug.com/100514 1733 // http://crbug.com/100514
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after
3360 const NavigationController& controller = web_contents->GetController(); 3423 const NavigationController& controller = web_contents->GetController();
3361 // First entry is about:blank, second is prerender_page.html. 3424 // First entry is about:blank, second is prerender_page.html.
3362 EXPECT_TRUE(controller.GetPendingEntry() == NULL); 3425 EXPECT_TRUE(controller.GetPendingEntry() == NULL);
3363 EXPECT_EQ(2, controller.GetEntryCount()); 3426 EXPECT_EQ(2, controller.GetEntryCount());
3364 EXPECT_EQ(GURL(content::kAboutBlankURL), 3427 EXPECT_EQ(GURL(content::kAboutBlankURL),
3365 controller.GetEntryAtIndex(0)->GetURL()); 3428 controller.GetEntryAtIndex(0)->GetURL());
3366 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL()); 3429 EXPECT_EQ(dest_url(), controller.GetEntryAtIndex(1)->GetURL());
3367 } 3430 }
3368 3431
3369 } // namespace prerender 3432 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698