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

Side by Side Diff: chrome/browser/search/instant_service_unittest.cc

Issue 20388003: Reload Instant NTP and Instant-process tabs on search url change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Format and lint Created 7 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 unified diff | Download patch
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 #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 using testing::_;
18
19 namespace chrome {
20
21 namespace {
22
23 class MockInstantServiceObserver : public InstantServiceObserver {
24 public:
25 MOCK_METHOD0(DefaultSearchProviderChanged, void());
26 MOCK_METHOD0(GoogleURLUpdated, void());
27 // TODO(skanuj@chromium.org) : Add more tests.
samarth 2013/08/12 19:07:28 That's like a TODO: make things better :) I'm def
Anuj 2013/08/13 00:18:09 Done.
28 // MOCK_METHOD1(ThemeInfoChanged, void(const ThemeBackgroundInfo&));
29 // MOCK_METHOD1(MostVisitedItemsChanged,
30 // void(const std::vector<InstantMostVisitedItem>&));
31 };
32
33 class MockWebContentsObserver : public content::WebContentsObserver {
34 public:
35 MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*));
36
37 protected:
38 friend class InstantServiceTest;
39 };
40
41 class InstantServiceTest : public InstantUnitTestBase {
42 protected:
43 virtual void SetUp() OVERRIDE {
44 InstantUnitTestBase::SetUp();
45
46 instant_service_observer_.reset(new MockInstantServiceObserver());
47 instant_service_->AddObserver(instant_service_observer());
48
49 instant_ntp_contents_observer_.reset(new MockWebContentsObserver());
50 instant_ntp_contents_observer()->Observe(
51 instant_service_->GetNTPContents());
52 }
53
54 MockInstantServiceObserver* instant_service_observer() {
55 return instant_service_observer_.get();
56 }
57
58 MockWebContentsObserver* instant_ntp_contents_observer() {
59 return instant_ntp_contents_observer_.get();
60 }
61
62 scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
63 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_;
64 };
65
66 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) {
67 EXPECT_CALL(*instant_service_observer(), DefaultSearchProviderChanged())
68 .Times(1);
69 EXPECT_CALL(*instant_ntp_contents_observer(),
70 WebContentsDestroyed(instant_service_->GetNTPContents()))
71 .Times(1);
72
73 GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
74 const std::string& new_base_url = "https://bar.com/";
75 SetSearchProvider(new_base_url);
76 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
77 EXPECT_NE(ntp_url, new_ntp_url);
78 EXPECT_TRUE(new_ntp_url.spec().find(new_base_url) == 0);
79 }
80
81 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) {
82 EXPECT_CALL(*instant_service_observer(), GoogleURLUpdated()).Times(1);
83 EXPECT_CALL(*instant_ntp_contents_observer(),
84 WebContentsDestroyed(instant_service_->GetNTPContents()))
85 .Times(1);
86
87 GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
88 const std::string& new_base_url = "https://www.google.es/";
89 NotifyGoogleBaseURLUpdate(new_base_url);
90 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
91 EXPECT_NE(ntp_url, new_ntp_url);
92 EXPECT_TRUE(new_ntp_url.spec().find(new_base_url) == 0);
93 }
94
95 } // namespace
96
97 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698