Chromium Code Reviews| 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 "chrome/browser/search/instant_service.h" | |
| 10 #include "chrome/browser/search/instant_service_observer.h" | |
| 11 #include "chrome/browser/search/instant_unittest_base.h" | |
| 12 #include "chrome/browser/search/search.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "content/public/browser/web_contents_observer.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 | |
| 17 namespace chrome { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class MockInstantServiceObserver : public InstantServiceObserver { | |
| 22 public: | |
| 23 MOCK_METHOD0(DefaultSearchProviderChanged, void()); | |
| 24 MOCK_METHOD0(GoogleURLUpdated, void()); | |
| 25 }; | |
| 26 | |
| 27 class MockWebContentsObserver : public content::WebContentsObserver { | |
| 28 public: | |
| 29 MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*)); | |
| 30 | |
| 31 protected: | |
| 32 friend class InstantServiceTest; | |
| 33 }; | |
| 34 | |
| 35 class InstantServiceTest : public InstantUnitTestBase { | |
| 36 protected: | |
| 37 virtual void SetUp() OVERRIDE { | |
| 38 InstantUnitTestBase::SetUp(); | |
| 39 | |
| 40 instant_service_observer_.reset(new MockInstantServiceObserver()); | |
| 41 instant_service_->AddObserver(instant_service_observer()); | |
| 42 | |
| 43 instant_ntp_contents_observer_.reset(new MockWebContentsObserver()); | |
| 44 instant_ntp_contents_observer()->Observe( | |
| 45 instant_service_->GetNTPContents()); | |
| 46 } | |
| 47 | |
| 48 MockInstantServiceObserver* instant_service_observer() { | |
| 49 return instant_service_observer_.get(); | |
| 50 } | |
| 51 | |
| 52 MockWebContentsObserver* instant_ntp_contents_observer() { | |
| 53 return instant_ntp_contents_observer_.get(); | |
| 54 } | |
| 55 | |
| 56 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; | |
| 57 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_; | |
| 58 }; | |
| 59 | |
| 60 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) { | |
| 61 EXPECT_CALL(*instant_service_observer(), DefaultSearchProviderChanged()) | |
| 62 .Times(1); | |
| 63 EXPECT_CALL(*instant_ntp_contents_observer(), | |
| 64 WebContentsDestroyed(instant_service_->GetNTPContents())) | |
| 65 .Times(1); | |
| 66 | |
| 67 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); | |
| 68 const std::string& new_base_url = "https://bar.com/"; | |
| 69 SetSearchProvider(new_base_url); | |
| 70 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); | |
| 71 EXPECT_NE(ntp_url, new_ntp_url); | |
| 72 EXPECT_TRUE(new_ntp_url.spec().find(new_base_url) == 0); | |
|
samarth
2013/08/14 00:24:14
nit: you could use EXPECT_THAT(..StartsWith(..))
Anuj
2013/08/14 06:38:57
Done.
| |
| 73 } | |
| 74 | |
| 75 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) { | |
| 76 EXPECT_CALL(*instant_service_observer(), GoogleURLUpdated()).Times(1); | |
| 77 EXPECT_CALL(*instant_ntp_contents_observer(), | |
| 78 WebContentsDestroyed(instant_service_->GetNTPContents())) | |
| 79 .Times(1); | |
| 80 | |
| 81 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); | |
| 82 const std::string& new_base_url = "https://www.google.es/"; | |
| 83 NotifyGoogleBaseURLUpdate(new_base_url); | |
| 84 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); | |
| 85 EXPECT_NE(ntp_url, new_ntp_url); | |
| 86 EXPECT_TRUE(new_ntp_url.spec().find(new_base_url) == 0); | |
| 87 } | |
| 88 | |
| 89 } // namespace | |
| 90 | |
| 91 } // namespace chrome | |
| OLD | NEW |