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

Side by Side Diff: chrome/browser/chrome_content_browser_client_browsertest.cc

Issue 22945004: InstantExtended: Add new_tab_url to TemplateURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 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/search/search.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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/metrics/field_trial.h"
6 #include "chrome/browser/search/search.h" 7 #include "chrome/browser/search/search.h"
8 #include "chrome/browser/search_engines/template_url_service.h"
9 #include "chrome/browser/search_engines/template_url_service_factory.h"
7 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
16 #include "url/gurl.h" 19 #include "url/gurl.h"
17 20
18 namespace content { 21 namespace content {
19 22
20 class ChromeContentBrowserClientBrowserTest : public InProcessBrowserTest { 23 class ChromeContentBrowserClientBrowserTest : public InProcessBrowserTest {
21 public: 24 public:
22 // Returns the last committed navigation entry of the first tab. May be NULL 25 // Returns the last committed navigation entry of the first tab. May be NULL
23 // if there is no such entry. 26 // if there is no such entry.
24 NavigationEntry* GetLastCommittedEntry() { 27 NavigationEntry* GetLastCommittedEntry() {
25 return browser()->tab_strip_model()->GetWebContentsAt(0)-> 28 return browser()->tab_strip_model()->GetWebContentsAt(0)->
26 GetController().GetLastCommittedEntry(); 29 GetController().GetLastCommittedEntry();
27 } 30 }
31
32 void InstallTemplateURLWithNewTabPage(GURL new_tab_page_url) {
33 TemplateURLService* template_url_service =
34 TemplateURLServiceFactory::GetForProfile(browser()->profile());
35 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
36
37 TemplateURLData data;
38 data.SetURL("http://foo.com/url?bar={searchTerms}");
39 data.new_tab_url = new_tab_page_url.spec();
40 TemplateURL* template_url = new TemplateURL(browser()->profile(), data);
41 // Takes ownership.
42 template_url_service->Add(template_url);
43 template_url_service->SetDefaultSearchProvider(template_url);
44 }
28 }; 45 };
29 46
30 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 47 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
31 UberURLHandler_SettingsPage) { 48 UberURLHandler_SettingsPage) {
32 const GURL url_short("chrome://settings/"); 49 const GURL url_short("chrome://settings/");
33 const GURL url_long("chrome://chrome/settings/"); 50 const GURL url_long("chrome://chrome/settings/");
34 51
35 ui_test_utils::NavigateToURL(browser(), url_short); 52 ui_test_utils::NavigateToURL(browser(), url_short);
36 NavigationEntry* entry = GetLastCommittedEntry(); 53 NavigationEntry* entry = GetLastCommittedEntry();
37 54
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 91
75 ASSERT_TRUE(entry != NULL); 92 ASSERT_TRUE(entry != NULL);
76 EXPECT_TRUE(entry->GetVirtualURL().is_valid()); 93 EXPECT_TRUE(entry->GetVirtualURL().is_valid());
77 EXPECT_EQ(url, entry->GetVirtualURL()); 94 EXPECT_EQ(url, entry->GetVirtualURL());
78 } 95 }
79 96
80 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 97 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
81 UberURLHandler_InstantExtendedNewTabPage) { 98 UberURLHandler_InstantExtendedNewTabPage) {
82 const GURL url_original("chrome://newtab"); 99 const GURL url_original("chrome://newtab");
83 const GURL url_rewritten("http://example.com/newtab"); 100 const GURL url_rewritten("http://example.com/newtab");
84 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 101 InstallTemplateURLWithNewTabPage(url_rewritten);
85 switches::kInstantNewTabURL, url_rewritten.spec()); 102 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
103 "Group1 use_cacheable_ntp:1"));
86 chrome::EnableInstantExtendedAPIForTesting(); 104 chrome::EnableInstantExtendedAPIForTesting();
87 105
88 ui_test_utils::NavigateToURL(browser(), url_original); 106 ui_test_utils::NavigateToURL(browser(), url_original);
89 NavigationEntry* entry = GetLastCommittedEntry(); 107 NavigationEntry* entry = GetLastCommittedEntry();
90 108
91 ASSERT_TRUE(entry != NULL); 109 ASSERT_TRUE(entry != NULL);
92 EXPECT_EQ(url_rewritten, entry->GetURL()); 110 EXPECT_EQ(url_rewritten, entry->GetURL());
93 EXPECT_EQ(url_original, entry->GetVirtualURL()); 111 EXPECT_EQ(url_original, entry->GetVirtualURL());
94 } 112 }
95 113
96 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 114 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
97 UberURLHandler_InstantExtendedNewTabPageDisabled) { 115 UberURLHandler_InstantExtendedNewTabPageDisabled) {
98 const GURL url_original("chrome://newtab"); 116 const GURL url_original("chrome://newtab");
99 const GURL url_rewritten("http://example.com/newtab"); 117 const GURL url_rewritten("http://example.com/newtab");
100 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 118 InstallTemplateURLWithNewTabPage(url_rewritten);
101 switches::kInstantNewTabURL, url_rewritten.spec()); 119 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
120 "Group1 use_cacheable_ntp:1"));
121 chrome::DisableInstantExtendedAPIForTesting();
102 122
103 ui_test_utils::NavigateToURL(browser(), url_original); 123 ui_test_utils::NavigateToURL(browser(), url_original);
104 NavigationEntry* entry = GetLastCommittedEntry(); 124 NavigationEntry* entry = GetLastCommittedEntry();
105 125
106 ASSERT_TRUE(entry != NULL); 126 ASSERT_TRUE(entry != NULL);
107 EXPECT_EQ(url_original, entry->GetURL()); 127 EXPECT_EQ(url_original, entry->GetURL());
108 EXPECT_EQ(url_original, entry->GetVirtualURL()); 128 EXPECT_EQ(url_original, entry->GetVirtualURL());
109 } 129 }
110 130
111 // Test that a basic navigation works in --site-per-process mode. This prevents 131 // Test that a basic navigation works in --site-per-process mode. This prevents
112 // regressions when that mode calls out into the ChromeContentBrowserClient, 132 // regressions when that mode calls out into the ChromeContentBrowserClient,
113 // such as http://crbug.com/164223. 133 // such as http://crbug.com/164223.
114 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 134 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
115 SitePerProcessNavigation) { 135 SitePerProcessNavigation) {
116 CommandLine::ForCurrentProcess()->AppendSwitch( 136 CommandLine::ForCurrentProcess()->AppendSwitch(
117 switches::kSitePerProcess); 137 switches::kSitePerProcess);
118 ASSERT_TRUE(test_server()->Start()); 138 ASSERT_TRUE(test_server()->Start());
119 const GURL url(test_server()->GetURL("files/title1.html")); 139 const GURL url(test_server()->GetURL("files/title1.html"));
120 140
121 ui_test_utils::NavigateToURL(browser(), url); 141 ui_test_utils::NavigateToURL(browser(), url);
122 NavigationEntry* entry = GetLastCommittedEntry(); 142 NavigationEntry* entry = GetLastCommittedEntry();
123 143
124 ASSERT_TRUE(entry != NULL); 144 ASSERT_TRUE(entry != NULL);
125 EXPECT_EQ(url, entry->GetURL()); 145 EXPECT_EQ(url, entry->GetURL());
126 EXPECT_EQ(url, entry->GetVirtualURL()); 146 EXPECT_EQ(url, entry->GetVirtualURL());
127 } 147 }
128 148
129 } // namespace content 149 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search/search.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698