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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac_browsertest.mm

Issue 12042002: Alternate NTP: Add search token to omnibox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 7 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
6
7 #import "chrome/browser/ui/browser_window.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h"
10 #import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12
13 namespace {
14
15 // Override the toolbar model to allow |GetInputInProgress| and
16 // |WouldReplaceSearchURLWithSearchTerms| to be customized.
17 class MockToolbarModel : public ToolbarModel {
18 public:
19 MockToolbarModel() : ToolbarModel(),
20 input_in_progress_(false),
21 would_replace_search_url_with_search_terms_(false) {}
22 virtual ~MockToolbarModel() {}
23
24 virtual string16 GetText(
25 bool display_search_urls_as_search_terms) const OVERRIDE {
26 return string16();
27 }
28 virtual GURL GetURL() const OVERRIDE { return GURL(); }
29 virtual bool WouldReplaceSearchURLWithSearchTerms() const OVERRIDE {
30 return would_replace_search_url_with_search_terms_;
31 }
32 virtual SecurityLevel GetSecurityLevel() const OVERRIDE { return NONE; }
33 virtual int GetIcon() const OVERRIDE { return 0; }
34 virtual string16 GetEVCertName() const OVERRIDE { return string16(); }
35 virtual bool ShouldDisplayURL() const OVERRIDE { return false; }
36 virtual void SetInputInProgress(bool value) OVERRIDE {
37 input_in_progress_ = value;
38 }
39 virtual bool GetInputInProgress() const OVERRIDE {
40 return input_in_progress_;
41 }
42
43 void set_would_replace_search_url_with_search_terms(bool value) {
44 would_replace_search_url_with_search_terms_ = value;
45 }
46
47 private:
48 bool input_in_progress_;
49 bool would_replace_search_url_with_search_terms_;
50 };
51
52 } // namespace
53
54 class LocationBarViewMacBrowserTest : public InProcessBrowserTest {
55 public:
56 LocationBarViewMacBrowserTest() : InProcessBrowserTest(),
57 old_toolbar_model_(NULL) {
58 }
59
60 protected:
61 virtual void SetUpOnMainThread() OVERRIDE {
62 old_toolbar_model_ = GetLocationBar()->toolbar_model_;
63 GetLocationBar()->toolbar_model_ = &mock_toolbar_model_;
64 }
65
66 virtual void CleanUpOnMainThread() OVERRIDE {
67 GetLocationBar()->toolbar_model_ = old_toolbar_model_;
68 }
69
70 LocationBarViewMac* GetLocationBar() const {
71 BrowserWindowController* controller =
72 [BrowserWindowController browserWindowControllerForWindow:
73 browser()->window()->GetNativeWindow()];
74 return [controller locationBarBridge];
75 }
76
77 SearchTokenDecoration* GetSearchTokenDecoration() const {
78 return GetLocationBar()->search_token_decoration_.get();
79 }
80
81 SeparatorDecoration* GetSeparatorDecoration() const {
82 return GetLocationBar()->separator_decoration_.get();
83 }
84
85 protected:
86 MockToolbarModel mock_toolbar_model_;
87
88 private:
89 ToolbarModel* old_toolbar_model_;
90
91 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMacBrowserTest);
92 };
93
94 // Verify that the search token decoration is displayed when there are search
95 // terms in the omnibox.
96 IN_PROC_BROWSER_TEST_F(LocationBarViewMacBrowserTest, SearchToken) {
97 GetLocationBar()->Layout();
98 EXPECT_FALSE(GetSearchTokenDecoration()->IsVisible());
99 EXPECT_FALSE(GetSeparatorDecoration()->IsVisible());
100
101 mock_toolbar_model_.SetInputInProgress(false);
102 mock_toolbar_model_.set_would_replace_search_url_with_search_terms(true);
103 GetLocationBar()->Layout();
104 EXPECT_TRUE(GetSearchTokenDecoration()->IsVisible());
105 EXPECT_TRUE(GetSeparatorDecoration()->IsVisible());
106
107 mock_toolbar_model_.SetInputInProgress(true);
108 GetLocationBar()->Layout();
109 EXPECT_FALSE(GetSearchTokenDecoration()->IsVisible());
110 EXPECT_FALSE(GetSeparatorDecoration()->IsVisible());
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698