| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 
| 6 | 6 | 
| 7 #import "chrome/browser/ui/browser_window.h" | 7 #import "chrome/browser/ui/browser_window.h" | 
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 
|  | 9 #include "chrome/browser/ui/cocoa/location_bar/mock_toolbar_model.h" | 
| 9 #import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h" | 
| 10 #import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h" | 
| 11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" | 
| 12 | 13 | 
| 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 { | 14 class LocationBarViewMacBrowserTest : public InProcessBrowserTest { | 
| 55  public: | 15  public: | 
| 56   LocationBarViewMacBrowserTest() : InProcessBrowserTest(), | 16   LocationBarViewMacBrowserTest() : InProcessBrowserTest(), | 
| 57                                     old_toolbar_model_(NULL) { | 17                                     old_toolbar_model_(NULL) { | 
| 58   } | 18   } | 
| 59 | 19 | 
| 60  protected: | 20  protected: | 
| 61   virtual void SetUpOnMainThread() OVERRIDE { | 21   virtual void SetUpOnMainThread() OVERRIDE { | 
| 62     old_toolbar_model_ = GetLocationBar()->toolbar_model_; | 22     old_toolbar_model_ = GetLocationBar()->toolbar_model_; | 
| 63     GetLocationBar()->toolbar_model_ = &mock_toolbar_model_; | 23     GetLocationBar()->toolbar_model_ = &mock_toolbar_model_; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 76 | 36 | 
| 77   SearchTokenDecoration* GetSearchTokenDecoration() const { | 37   SearchTokenDecoration* GetSearchTokenDecoration() const { | 
| 78     return GetLocationBar()->search_token_decoration_.get(); | 38     return GetLocationBar()->search_token_decoration_.get(); | 
| 79   } | 39   } | 
| 80 | 40 | 
| 81   SeparatorDecoration* GetSeparatorDecoration() const { | 41   SeparatorDecoration* GetSeparatorDecoration() const { | 
| 82     return GetLocationBar()->separator_decoration_.get(); | 42     return GetLocationBar()->separator_decoration_.get(); | 
| 83   } | 43   } | 
| 84 | 44 | 
| 85  protected: | 45  protected: | 
| 86   MockToolbarModel mock_toolbar_model_; | 46   chrome::testing::MockToolbarModel mock_toolbar_model_; | 
| 87 | 47 | 
| 88  private: | 48  private: | 
| 89   ToolbarModel* old_toolbar_model_; | 49   ToolbarModel* old_toolbar_model_; | 
| 90 | 50 | 
| 91   DISALLOW_COPY_AND_ASSIGN(LocationBarViewMacBrowserTest); | 51   DISALLOW_COPY_AND_ASSIGN(LocationBarViewMacBrowserTest); | 
| 92 }; | 52 }; | 
| 93 | 53 | 
| 94 // Verify that the search token decoration is displayed when there are search | 54 // Verify that the search token decoration is displayed when there are search | 
| 95 // terms in the omnibox. | 55 // terms in the omnibox. | 
| 96 IN_PROC_BROWSER_TEST_F(LocationBarViewMacBrowserTest, SearchToken) { | 56 IN_PROC_BROWSER_TEST_F(LocationBarViewMacBrowserTest, SearchToken) { | 
| 97   GetLocationBar()->Layout(); | 57   GetLocationBar()->Layout(); | 
| 98   EXPECT_FALSE(GetSearchTokenDecoration()->IsVisible()); | 58   EXPECT_FALSE(GetSearchTokenDecoration()->IsVisible()); | 
| 99   EXPECT_FALSE(GetSeparatorDecoration()->IsVisible()); | 59   EXPECT_FALSE(GetSeparatorDecoration()->IsVisible()); | 
| 100 | 60 | 
| 101   mock_toolbar_model_.SetInputInProgress(false); | 61   mock_toolbar_model_.SetInputInProgress(false); | 
| 102   mock_toolbar_model_.set_would_replace_search_url_with_search_terms(true); | 62   mock_toolbar_model_.set_would_replace_search_url_with_search_terms(true); | 
| 103   GetLocationBar()->Layout(); | 63   GetLocationBar()->Layout(); | 
| 104   EXPECT_TRUE(GetSearchTokenDecoration()->IsVisible()); | 64   EXPECT_TRUE(GetSearchTokenDecoration()->IsVisible()); | 
| 105   EXPECT_TRUE(GetSeparatorDecoration()->IsVisible()); | 65   EXPECT_TRUE(GetSeparatorDecoration()->IsVisible()); | 
| 106 | 66 | 
| 107   mock_toolbar_model_.SetInputInProgress(true); | 67   mock_toolbar_model_.SetInputInProgress(true); | 
| 108   GetLocationBar()->Layout(); | 68   GetLocationBar()->Layout(); | 
| 109   EXPECT_FALSE(GetSearchTokenDecoration()->IsVisible()); | 69   EXPECT_FALSE(GetSearchTokenDecoration()->IsVisible()); | 
| 110   EXPECT_FALSE(GetSeparatorDecoration()->IsVisible()); | 70   EXPECT_FALSE(GetSeparatorDecoration()->IsVisible()); | 
| 111 } | 71 } | 
| OLD | NEW | 
|---|