OLD | NEW |
(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 #include <string> |
| 6 #include <vector> |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/search/instant_service.h" |
| 11 #include "chrome/browser/search/instant_service_observer.h" |
| 12 #include "chrome/browser/search/instant_unittest_base.h" |
| 13 #include "chrome/browser/search/search.h" |
| 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/host_desktop.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 |
| 21 namespace chrome { |
| 22 |
| 23 namespace { |
| 24 |
| 25 class MockInstantServiceObserver : public InstantServiceObserver { |
| 26 public: |
| 27 MOCK_METHOD0(DefaultSearchProviderChanged, void()); |
| 28 MOCK_METHOD0(GoogleURLUpdated, void()); |
| 29 }; |
| 30 |
| 31 class MockWebContentsObserver : public content::WebContentsObserver { |
| 32 public: |
| 33 MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*)); |
| 34 |
| 35 // Dumb override to make MSVC happy. |
| 36 void Observe_(content::WebContents* contents) { |
| 37 content::WebContentsObserver::Observe(contents); |
| 38 } |
| 39 |
| 40 protected: |
| 41 friend class InstantServiceTest; |
| 42 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, |
| 43 DispatchDefaultSearchProviderChanged); |
| 44 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated); |
| 45 }; |
| 46 |
| 47 class InstantServiceTest : public InstantUnitTestBase { |
| 48 protected: |
| 49 virtual void SetUp() OVERRIDE { |
| 50 InstantUnitTestBase::SetUp(); |
| 51 |
| 52 instant_service_observer_.reset(new MockInstantServiceObserver()); |
| 53 instant_service_->AddObserver(instant_service_observer_.get()); |
| 54 |
| 55 instant_ntp_contents_observer_.reset(new MockWebContentsObserver()); |
| 56 instant_ntp_contents_observer_->Observe_( |
| 57 instant_service_->GetNTPContents()); |
| 58 } |
| 59 |
| 60 virtual void TearDown() OVERRIDE { |
| 61 instant_service_->RemoveObserver(instant_service_observer_.get()); |
| 62 instant_ntp_contents_observer_->Observe_(NULL); |
| 63 InstantUnitTestBase::TearDown(); |
| 64 } |
| 65 |
| 66 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; |
| 67 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_; |
| 68 }; |
| 69 |
| 70 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) { |
| 71 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) |
| 72 .Times(1); |
| 73 EXPECT_CALL(*instant_ntp_contents_observer_.get(), |
| 74 WebContentsDestroyed(instant_service_->GetNTPContents())) |
| 75 .Times(1); |
| 76 |
| 77 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| 78 const std::string& new_base_url = "https://bar.com/"; |
| 79 SetDefaultSearchProvider(new_base_url); |
| 80 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| 81 EXPECT_NE(ntp_url, new_ntp_url); |
| 82 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true)); |
| 83 } |
| 84 |
| 85 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) { |
| 86 EXPECT_CALL(*instant_service_observer_.get(), GoogleURLUpdated()).Times(1); |
| 87 EXPECT_CALL(*instant_ntp_contents_observer_.get(), |
| 88 WebContentsDestroyed(instant_service_->GetNTPContents())) |
| 89 .Times(1); |
| 90 |
| 91 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| 92 const std::string& new_base_url = "https://www.google.es/"; |
| 93 NotifyGoogleBaseURLUpdate(new_base_url); |
| 94 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| 95 EXPECT_NE(ntp_url, new_ntp_url); |
| 96 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true)); |
| 97 } |
| 98 |
| 99 } // namespace |
| 100 |
| 101 } // namespace chrome |
OLD | NEW |