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

Unified Diff: chrome/browser/ui/toolbar/toolbar_model_unittest.cc

Issue 10867038: A simple version of search term replacement for testing . (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added whitespace 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/toolbar_model_unittest.cc
diff --git a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
index 5c1e49debc39665f4c1df674a22a5c826dff9196..9a5405832dc9152242584f0465fe9c99ce289f0e 100644
--- a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
@@ -1,13 +1,18 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/toolbar/toolbar_model.h"
+#include "base/command_line.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
@@ -16,42 +21,181 @@ using content::OpenURLParams;
using content::Referrer;
using content::WebContents;
+namespace {
+
+struct TestItem {
+ GURL url;
+ string16 expected_text;
+ // The expected text to display when Extended Instant is inactive.
+ string16 expected_replace_text_inactive;
+ // The expected text to display when Extended Instant is active.
+ string16 expected_replace_text_active;
+ bool would_replace;
+ bool should_display;
+} test_items[] = {
+ {
+ GURL("view-source:http://www.google.com"),
+ ASCIIToUTF16("view-source:www.google.com"),
+ ASCIIToUTF16("view-source:www.google.com"),
+ ASCIIToUTF16("view-source:www.google.com"),
+ false,
+ true
+ },
+ {
+ GURL("view-source:chrome://newtab/"),
+ ASCIIToUTF16("view-source:chrome://newtab"),
+ ASCIIToUTF16("view-source:chrome://newtab"),
+ ASCIIToUTF16("view-source:chrome://newtab"),
+ false,
+ true
+ },
+ {
+ GURL("chrome-extension://monkey/balls.html"),
+ string16(),
+ string16(),
+ string16(),
+ false,
+ false
+ },
+ {
+ GURL("chrome://newtab/"),
+ string16(),
+ string16(),
+ string16(),
+ false,
+ false
+ },
+ {
+ GURL(chrome::kAboutBlankURL),
+ ASCIIToUTF16(chrome::kAboutBlankURL),
+ ASCIIToUTF16(chrome::kAboutBlankURL),
+ ASCIIToUTF16(chrome::kAboutBlankURL),
+ false,
+ true
+ },
+ {
+ GURL("http://searchurl/?q=tractor+supply"),
+ ASCIIToUTF16("searchurl/?q=tractor+supply"),
+ ASCIIToUTF16("searchurl/?q=tractor+supply"),
+ ASCIIToUTF16("searchurl/?q=tractor+supply"),
+ false,
+ true
+ },
+ {
+ GURL("http://google.com/search?q=tractor+supply"),
+ ASCIIToUTF16("google.com/search?q=tractor+supply"),
+ ASCIIToUTF16("google.com/search?q=tractor+supply"),
+ ASCIIToUTF16("google.com/search?q=tractor+supply"),
+ false,
+ true
+ },
+ {
+ GURL("http://google.com/search?q=tractor+supply&espv=1"),
+ ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"),
+ ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"),
+ ASCIIToUTF16("tractor supply"),
+ true,
+ true
+ }
+};
+
+} // end namespace
+
class ToolbarModelTest : public BrowserWithTestWindowTest {
public:
ToolbarModelTest() {}
+ virtual void SetUp() OVERRIDE {
+ BrowserWithTestWindowTest::SetUp();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile(), &TemplateURLServiceFactory::BuildInstanceFor);
+ }
+ virtual void TearDown() OVERRIDE { BrowserWithTestWindowTest::TearDown(); }
+
protected:
- void NavigateAndCheckText(const std::string& url,
- const std::string& expected_text,
+
+ void ResetDefaultTemplateURL() {
+ TemplateURLData data;
+ data.SetURL("http://google.com/search?q={searchTerms}");
+ TemplateURL* search_template_url = new TemplateURL(profile(), data);
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile());
+ template_url_service->Add(search_template_url);
+ template_url_service->SetDefaultSearchProvider(search_template_url);
+ ASSERT_NE(0, search_template_url->id());
+ template_url_service->Load();
+ }
+
+ void NavigateAndCheckText(const GURL& url,
+ const string16& expected_text,
+ const string16& expected_replace_text,
+ bool would_replace,
bool should_display) {
+ NavigateAndCheckTextImpl(url, false, expected_text, would_replace,
+ should_display);
+ NavigateAndCheckTextImpl(url, true, expected_replace_text, would_replace,
+ should_display);
+ }
+
+ private:
+ void NavigateAndCheckTextImpl(const GURL& url,
+ bool can_replace,
+ const string16 expected_text,
+ bool would_replace,
+ bool should_display) {
WebContents* contents = chrome::GetWebContentsAt(browser(), 0);
browser()->OpenURL(OpenURLParams(
- GURL(url), Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED,
+ url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED,
false));
+ ToolbarModel* toolbar_model = browser()->toolbar_model();
+
// Check while loading.
- EXPECT_EQ(should_display, browser()->toolbar_model()->ShouldDisplayURL());
- EXPECT_EQ(ASCIIToUTF16(expected_text),
- browser()->toolbar_model()->GetText());
+ EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL());
+ EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace));
+ EXPECT_EQ(would_replace,
+ toolbar_model->WouldReplaceSearchURLWithSearchTerms());
// Check after commit.
CommitPendingLoad(&contents->GetController());
- EXPECT_EQ(should_display, browser()->toolbar_model()->ShouldDisplayURL());
- EXPECT_EQ(ASCIIToUTF16(expected_text),
- browser()->toolbar_model()->GetText());
+ EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL());
+ EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace));
+ EXPECT_EQ(would_replace,
+ toolbar_model->WouldReplaceSearchURLWithSearchTerms());
}
};
-// Test that URLs are correctly shown or hidden both during navigation and
-// after commit.
-TEST_F(ToolbarModelTest, ShouldDisplayURL) {
+// Test that we don't replace any URLs when the InstantExtended API is disabled.
+TEST_F(ToolbarModelTest, ShouldDisplayURLInstantExtendedAPIDisabled) {
+ ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableInstantExtendedAPI))
+ << "This test expects Extended Instant to be disabled.";
+
+ ResetDefaultTemplateURL();
AddTab(browser(), GURL(chrome::kAboutBlankURL));
+ for (size_t i = 0; i < arraysize(test_items); ++i) {
+ const TestItem& test_item = test_items[i];
+ NavigateAndCheckText(test_item.url,
+ test_item.expected_text,
+ test_item.expected_replace_text_inactive,
+ false,
+ test_item.should_display);
+ }
+}
+
+// Test that we don't replace any URLs when the InstantExtended API is enabled.
+TEST_F(ToolbarModelTest, ShouldDisplayURLInstantExtendedAPIEnabled) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableInstantExtendedAPI);
- NavigateAndCheckText("view-source:http://www.google.com",
- "view-source:www.google.com", true);
- NavigateAndCheckText("view-source:chrome://newtab/",
- "view-source:chrome://newtab", true);
- NavigateAndCheckText("chrome-extension://monkey/balls.html", "", false);
- NavigateAndCheckText("chrome://newtab/", "", false);
- NavigateAndCheckText(chrome::kAboutBlankURL, chrome::kAboutBlankURL, true);
+ ResetDefaultTemplateURL();
+ AddTab(browser(), GURL(chrome::kAboutBlankURL));
+ for (size_t i = 0; i < arraysize(test_items); ++i) {
+ const TestItem& test_item = test_items[i];
+ NavigateAndCheckText(test_item.url,
+ test_item.expected_text,
+ test_item.expected_replace_text_active,
+ test_item.would_replace,
+ test_item.should_display);
+ }
}
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model.cc ('k') | chrome/browser/ui/views/location_bar/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698