| 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 "chrome/browser/ui/toolbar/toolbar_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/instant/instant_service.h" |
| 10 #include "chrome/browser/instant/instant_service_factory.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 11 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 12 #include "chrome/browser/search_engines/template_url_service.h" |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 13 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/search/search.h" | 15 #include "chrome/browser/ui/search/search.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 16 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/test/base/browser_with_test_window_test.h" | 19 #include "chrome/test/base/browser_with_test_window_test.h" |
| 20 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 20 | 23 |
| 21 using content::OpenURLParams; | 24 using content::OpenURLParams; |
| 22 using content::Referrer; | 25 using content::Referrer; |
| 23 using content::WebContents; | 26 using content::WebContents; |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 struct TestItem { | 30 struct TestItem { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 122 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 120 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 123 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
| 121 } | 124 } |
| 122 virtual void TearDown() OVERRIDE { BrowserWithTestWindowTest::TearDown(); } | 125 virtual void TearDown() OVERRIDE { BrowserWithTestWindowTest::TearDown(); } |
| 123 | 126 |
| 124 protected: | 127 protected: |
| 125 | 128 |
| 126 void ResetDefaultTemplateURL() { | 129 void ResetDefaultTemplateURL() { |
| 127 TemplateURLData data; | 130 TemplateURLData data; |
| 128 data.SetURL("http://google.com/search?q={searchTerms}"); | 131 data.SetURL("http://google.com/search?q={searchTerms}"); |
| 132 data.instant_url = "http://does/not/exist"; |
| 129 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}"; | 133 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}"; |
| 130 TemplateURL* search_template_url = new TemplateURL(profile(), data); | 134 TemplateURL* search_template_url = new TemplateURL(profile(), data); |
| 131 TemplateURLService* template_url_service = | 135 TemplateURLService* template_url_service = |
| 132 TemplateURLServiceFactory::GetForProfile(profile()); | 136 TemplateURLServiceFactory::GetForProfile(profile()); |
| 133 template_url_service->Add(search_template_url); | 137 template_url_service->Add(search_template_url); |
| 134 template_url_service->SetDefaultSearchProvider(search_template_url); | 138 template_url_service->SetDefaultSearchProvider(search_template_url); |
| 135 ASSERT_NE(0, search_template_url->id()); | 139 ASSERT_NE(0, search_template_url->id()); |
| 136 template_url_service->Load(); | 140 template_url_service->Load(); |
| 137 } | 141 } |
| 138 | 142 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 151 void NavigateAndCheckTextImpl(const GURL& url, | 155 void NavigateAndCheckTextImpl(const GURL& url, |
| 152 bool can_replace, | 156 bool can_replace, |
| 153 const string16 expected_text, | 157 const string16 expected_text, |
| 154 bool would_replace, | 158 bool would_replace, |
| 155 bool should_display) { | 159 bool should_display) { |
| 156 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); | 160 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 157 browser()->OpenURL(OpenURLParams( | 161 browser()->OpenURL(OpenURLParams( |
| 158 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | 162 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 159 false)); | 163 false)); |
| 160 | 164 |
| 165 // Query terms replacement requires that the renderer process be a |
| 166 // recognized Instant renderer. Fake it. |
| 167 InstantService* instant_service = |
| 168 InstantServiceFactory::GetForProfile(profile()); |
| 169 int process_id = contents->GetRenderProcessHost()->GetID(); |
| 170 instant_service->AddInstantProcess(process_id); |
| 171 |
| 161 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 172 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 162 | 173 |
| 163 // Check while loading. | 174 // Check while loading. |
| 164 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); | 175 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); |
| 165 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); | 176 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); |
| 166 EXPECT_EQ(would_replace, | 177 EXPECT_EQ(would_replace, |
| 167 toolbar_model->WouldReplaceSearchURLWithSearchTerms()); | 178 toolbar_model->WouldReplaceSearchURLWithSearchTerms()); |
| 168 | 179 |
| 169 // Check after commit. | 180 // Check after commit. |
| 170 CommitPendingLoad(&contents->GetController()); | 181 CommitPendingLoad(&contents->GetController()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 200 AddTab(browser(), GURL(chrome::kAboutBlankURL)); | 211 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
| 201 for (size_t i = 0; i < arraysize(test_items); ++i) { | 212 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 202 const TestItem& test_item = test_items[i]; | 213 const TestItem& test_item = test_items[i]; |
| 203 NavigateAndCheckText(test_item.url, | 214 NavigateAndCheckText(test_item.url, |
| 204 test_item.expected_text, | 215 test_item.expected_text, |
| 205 test_item.expected_replace_text_active, | 216 test_item.expected_replace_text_active, |
| 206 test_item.would_replace, | 217 test_item.would_replace, |
| 207 test_item.should_display); | 218 test_item.should_display); |
| 208 } | 219 } |
| 209 } | 220 } |
| OLD | NEW |