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

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

Issue 10826110: Modify prerendering to support having multiple session storage namespaces per tab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | chrome/browser/prerender/prerender_contents.h » ('j') | 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 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 28 matching lines...) Expand all
39 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
40 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
41 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
42 #include "chrome/test/base/in_process_browser_test.h" 42 #include "chrome/test/base/in_process_browser_test.h"
43 #include "chrome/test/base/ui_test_utils.h" 43 #include "chrome/test/base/ui_test_utils.h"
44 #include "content/public/browser/devtools_agent_host_registry.h" 44 #include "content/public/browser/devtools_agent_host_registry.h"
45 #include "content/public/browser/devtools_client_host.h" 45 #include "content/public/browser/devtools_client_host.h"
46 #include "content/public/browser/devtools_manager.h" 46 #include "content/public/browser/devtools_manager.h"
47 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
49 #include "content/public/browser/session_storage_namespace.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
50 #include "content/public/common/url_constants.h" 51 #include "content/public/common/url_constants.h"
51 #include "content/public/test/browser_test_utils.h" 52 #include "content/public/test/browser_test_utils.h"
52 #include "content/public/test/test_navigation_observer.h" 53 #include "content/public/test/test_navigation_observer.h"
53 #include "content/public/test/test_utils.h" 54 #include "content/public/test/test_utils.h"
54 #include "grit/generated_resources.h" 55 #include "grit/generated_resources.h"
55 #include "net/base/mock_host_resolver.h" 56 #include "net/base/mock_host_resolver.h"
56 #include "net/url_request/url_request_context.h" 57 #include "net/url_request/url_request_context.h"
57 #include "net/url_request/url_request_context_getter.h" 58 #include "net/url_request/url_request_context_getter.h"
58 #include "ui/base/l10n/l10n_util.h" 59 #include "ui/base/l10n/l10n_util.h"
59 60
60 using content::BrowserThread; 61 using content::BrowserThread;
62 using content::SessionStorageNamespaceMap;
61 using content::DevToolsAgentHost; 63 using content::DevToolsAgentHost;
62 using content::DevToolsAgentHostRegistry; 64 using content::DevToolsAgentHostRegistry;
63 using content::DevToolsClientHost; 65 using content::DevToolsClientHost;
64 using content::DevToolsManager; 66 using content::DevToolsManager;
65 using content::NavigationController; 67 using content::NavigationController;
66 using content::OpenURLParams; 68 using content::OpenURLParams;
67 using content::Referrer; 69 using content::Referrer;
68 using content::RenderViewHost; 70 using content::RenderViewHost;
69 using content::RenderWidgetHost; 71 using content::RenderWidgetHost;
70 using content::WebContents; 72 using content::WebContents;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const gfx::Size& size) OVERRIDE { 241 const gfx::Size& size) OVERRIDE {
240 PrerenderContents::AddPendingPrerender( 242 PrerenderContents::AddPendingPrerender(
241 weak_prerender_handle, url, referrer, size); 243 weak_prerender_handle, url, referrer, size);
242 if (expected_pending_prerenders_ > 0 && 244 if (expected_pending_prerenders_ > 0 &&
243 pending_prerenders().size() == expected_pending_prerenders_) { 245 pending_prerenders().size() == expected_pending_prerenders_) {
244 MessageLoop::current()->Quit(); 246 MessageLoop::current()->Quit();
245 } 247 }
246 } 248 }
247 249
248 virtual WebContents* CreateWebContents( 250 virtual WebContents* CreateWebContents(
249 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { 251 const SessionStorageNamespaceMap& session_storage_namespace_map)
252 OVERRIDE {
250 WebContents* web_contents = PrerenderContents::CreateWebContents( 253 WebContents* web_contents = PrerenderContents::CreateWebContents(
251 session_storage_namespace); 254 session_storage_namespace_map);
252 string16 ready_title = ASCIIToUTF16(kReadyTitle); 255 string16 ready_title = ASCIIToUTF16(kReadyTitle);
253 if (prerender_should_wait_for_ready_title_) 256 if (prerender_should_wait_for_ready_title_)
254 ready_title_watcher_.reset(new content::TitleWatcher( 257 ready_title_watcher_.reset(new content::TitleWatcher(
255 web_contents, ready_title)); 258 web_contents, ready_title));
256 return web_contents; 259 return web_contents;
257 } 260 }
258 261
259 void WaitForPrerenderToHaveReadyTitleIfRequired() { 262 void WaitForPrerenderToHaveReadyTitleIfRequired() {
260 if (ready_title_watcher_.get()) { 263 if (ready_title_watcher_.get()) {
261 string16 ready_title = ASCIIToUTF16(kReadyTitle); 264 string16 ready_title = ASCIIToUTF16(kReadyTitle);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 #if defined(ENABLE_SAFE_BROWSING) 513 #if defined(ENABLE_SAFE_BROWSING)
511 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), 514 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()),
512 #endif 515 #endif
513 use_https_src_server_(false), 516 use_https_src_server_(false),
514 call_javascript_(true), 517 call_javascript_(true),
515 loader_path_("files/prerender/prerender_loader.html"), 518 loader_path_("files/prerender/prerender_loader.html"),
516 explicitly_set_browser_(NULL) {} 519 explicitly_set_browser_(NULL) {}
517 520
518 virtual ~PrerenderBrowserTest() {} 521 virtual ~PrerenderBrowserTest() {}
519 522
520 content::SessionStorageNamespace* GetSessionStorageNamespace() const { 523 const SessionStorageNamespaceMap& GetSessionStorageNamespaceMap() const {
521 TabContents* tab_contents = 524 TabContents* tab_contents =
522 current_browser()->tab_strip_model()->GetActiveTabContents(); 525 current_browser()->tab_strip_model()->GetActiveTabContents();
523 if (!tab_contents) 526 if (!tab_contents)
524 return NULL; 527 return kEmptyMap;
525 return tab_contents->web_contents()->GetController() 528 return tab_contents->web_contents()->GetController()
526 .GetSessionStorageNamespaceMap().find("")->second; 529 .GetSessionStorageNamespaceMap();
527 } 530 }
528 531
529 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 532 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
530 #if defined(ENABLE_SAFE_BROWSING) 533 #if defined(ENABLE_SAFE_BROWSING)
531 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); 534 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get());
532 #endif 535 #endif
533 } 536 }
534 537
535 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 538 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
536 command_line->AppendSwitchASCII(switches::kPrerenderMode, 539 command_line->AppendSwitchASCII(switches::kPrerenderMode,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 GURL dest_url = test_server()->GetURL(dest_html_file); 740 GURL dest_url = test_server()->GetURL(dest_html_file);
738 NavigateToURLImpl(dest_url, CURRENT_TAB); 741 NavigateToURLImpl(dest_url, CURRENT_TAB);
739 } 742 }
740 743
741 bool UrlIsInPrerenderManager(const std::string& html_file) const { 744 bool UrlIsInPrerenderManager(const std::string& html_file) const {
742 return UrlIsInPrerenderManager(test_server()->GetURL(html_file)); 745 return UrlIsInPrerenderManager(test_server()->GetURL(html_file));
743 } 746 }
744 747
745 bool UrlIsInPrerenderManager(const GURL& url) const { 748 bool UrlIsInPrerenderManager(const GURL& url) const {
746 return GetPrerenderManager()->FindPrerenderData( 749 return GetPrerenderManager()->FindPrerenderData(
747 url, GetSessionStorageNamespace()) != NULL; 750 url, GetSessionStorageNamespaceMap()) != NULL;
748 } 751 }
749 752
750 // This only checks to see if the URL is pending in our TestPrerenderContents. 753 // This only checks to see if the URL is pending in our TestPrerenderContents.
751 bool UrlIsPending(const std::string& html_file) const { 754 bool UrlIsPending(const std::string& html_file) const {
752 TestPrerenderContents* test_prerender_contents = GetPrerenderContents(); 755 TestPrerenderContents* test_prerender_contents = GetPrerenderContents();
753 if (!test_prerender_contents) 756 if (!test_prerender_contents)
754 return false; 757 return false;
755 GURL dest_url = test_server()->GetURL(html_file); 758 GURL dest_url = test_server()->GetURL(html_file);
756 return test_prerender_contents->UrlIsPending(dest_url); 759 return test_prerender_contents->UrlIsPending(dest_url);
757 } 760 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 802
800 #if defined(ENABLE_SAFE_BROWSING) 803 #if defined(ENABLE_SAFE_BROWSING)
801 FakeSafeBrowsingService* GetSafeBrowsingService() { 804 FakeSafeBrowsingService* GetSafeBrowsingService() {
802 return safe_browsing_factory_->most_recent_service(); 805 return safe_browsing_factory_->most_recent_service();
803 } 806 }
804 #endif 807 #endif
805 808
806 TestPrerenderContents* GetPrerenderContents() const { 809 TestPrerenderContents* GetPrerenderContents() const {
807 PrerenderManager::PrerenderData* prerender_data = 810 PrerenderManager::PrerenderData* prerender_data =
808 GetPrerenderManager()->FindPrerenderData( 811 GetPrerenderManager()->FindPrerenderData(
809 dest_url_, GetSessionStorageNamespace()); 812 dest_url_, GetSessionStorageNamespaceMap());
810 return static_cast<TestPrerenderContents*>( 813 return static_cast<TestPrerenderContents*>(
811 prerender_data ? prerender_data->contents() : NULL); 814 prerender_data ? prerender_data->contents() : NULL);
812 } 815 }
813 816
814 void set_loader_path(const std::string& path) { 817 void set_loader_path(const std::string& path) {
815 loader_path_ = path; 818 loader_path_ = path;
816 } 819 }
817 820
818 void set_loader_query_and_fragment(const std::string& query_and_fragment) { 821 void set_loader_query_and_fragment(const std::string& query_and_fragment) {
819 loader_query_and_fragment_ = query_and_fragment; 822 loader_query_and_fragment_ = query_and_fragment;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; 1031 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_;
1029 #if defined(ENABLE_SAFE_BROWSING) 1032 #if defined(ENABLE_SAFE_BROWSING)
1030 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; 1033 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_;
1031 #endif 1034 #endif
1032 GURL dest_url_; 1035 GURL dest_url_;
1033 bool use_https_src_server_; 1036 bool use_https_src_server_;
1034 bool call_javascript_; 1037 bool call_javascript_;
1035 std::string loader_path_; 1038 std::string loader_path_;
1036 std::string loader_query_and_fragment_; 1039 std::string loader_query_and_fragment_;
1037 Browser* explicitly_set_browser_; 1040 Browser* explicitly_set_browser_;
1041 const SessionStorageNamespaceMap kEmptyMap; // Used for an error return.
1038 }; 1042 };
1039 1043
1040 // Checks that a page is correctly prerendered in the case of a 1044 // Checks that a page is correctly prerendered in the case of a
1041 // <link rel=prerender> tag and then loaded into a tab in response to a 1045 // <link rel=prerender> tag and then loaded into a tab in response to a
1042 // navigation. 1046 // navigation.
1043 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { 1047 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
1044 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 1048 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
1045 NavigateToDestURL(); 1049 NavigateToDestURL();
1046 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 1050 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
1047 } 1051 }
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 ResultCatcher catcher; 2387 ResultCatcher catcher;
2384 2388
2385 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 2389 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
2386 NavigateToDestURL(); 2390 NavigateToDestURL();
2387 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 2391 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
2388 2392
2389 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 2393 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
2390 } 2394 }
2391 2395
2392 } // namespace prerender 2396 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698