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

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

Issue 132733002: InstantExtended: remove dead code related to the non-cacheable NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
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 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "chrome/browser/search/instant_service.h" 11 #include "chrome/browser/search/instant_service.h"
12 #include "chrome/browser/search/instant_service_observer.h" 12 #include "chrome/browser/search/instant_service_observer.h"
13 #include "chrome/browser/search/instant_unittest_base.h" 13 #include "chrome/browser/search/instant_unittest_base.h"
14 #include "chrome/browser/search/search.h" 14 #include "chrome/browser/search/search.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/host_desktop.h" 17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/browser/ui/search/instant_search_prerenderer.h" 18 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
19 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
20 #include "components/variations/entropy_provider.h" 20 #include "components/variations/entropy_provider.h"
21 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
kmadhusu 2014/01/09 23:31:43 You can remove this and web_contents_observer.h
samarth 2014/01/10 05:13:32 Done.
24 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/test/mock_render_process_host.h" 25 #include "content/public/test/mock_render_process_host.h"
26 #include "ipc/ipc_message.h" 26 #include "ipc/ipc_message.h"
27 #include "ipc/ipc_test_sink.h" 27 #include "ipc/ipc_test_sink.h"
28 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 class MockInstantServiceObserver : public InstantServiceObserver { 31 class MockInstantServiceObserver : public InstantServiceObserver {
32 public: 32 public:
33 MOCK_METHOD0(DefaultSearchProviderChanged, void()); 33 MOCK_METHOD0(DefaultSearchProviderChanged, void());
34 MOCK_METHOD0(GoogleURLUpdated, void()); 34 MOCK_METHOD0(GoogleURLUpdated, void());
35 }; 35 };
36 36
37 class MockWebContentsObserver : public content::WebContentsObserver {
38 public:
39 MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*));
40
41 // Dumb override to make MSVC happy.
42 void Observe_(content::WebContents* contents) {
43 content::WebContentsObserver::Observe(contents);
44 }
45
46 protected:
47 friend class InstantServiceTest;
48 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest,
49 DispatchDefaultSearchProviderChanged);
50 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated);
51 };
52
53 class InstantServiceTest : public InstantUnitTestBase { 37 class InstantServiceTest : public InstantUnitTestBase {
54 protected: 38 protected:
55 virtual void SetUp() OVERRIDE { 39 virtual void SetUp() OVERRIDE {
56 InstantUnitTestBase::SetUpWithoutCacheableNTP(); 40 InstantUnitTestBase::SetUpWithoutCacheableNTP();
57 41
58 instant_service_observer_.reset(new MockInstantServiceObserver()); 42 instant_service_observer_.reset(new MockInstantServiceObserver());
59 instant_service_->AddObserver(instant_service_observer_.get()); 43 instant_service_->AddObserver(instant_service_observer_.get());
60
61 instant_ntp_contents_observer_.reset(new MockWebContentsObserver());
62 instant_ntp_contents_observer_->Observe_(
63 instant_service_->GetNTPContents());
64 } 44 }
65 45
66 virtual void TearDown() OVERRIDE { 46 virtual void TearDown() OVERRIDE {
67 instant_service_->RemoveObserver(instant_service_observer_.get()); 47 instant_service_->RemoveObserver(instant_service_observer_.get());
68 instant_ntp_contents_observer_->Observe_(NULL);
69 InstantUnitTestBase::TearDown(); 48 InstantUnitTestBase::TearDown();
70 } 49 }
71 50
72 InstantSearchPrerenderer* GetInstantSearchPrerenderer() { 51 InstantSearchPrerenderer* GetInstantSearchPrerenderer() {
73 return instant_service_->instant_search_prerenderer(); 52 return instant_service_->instant_search_prerenderer();
74 } 53 }
75 54
76 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; 55 scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
77 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_;
78 }; 56 };
79 57
80 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) { 58 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) {
81 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) 59 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged())
82 .Times(1); 60 .Times(1);
83 EXPECT_CALL(*instant_ntp_contents_observer_.get(),
84 WebContentsDestroyed(instant_service_->GetNTPContents()))
85 .Times(1);
86 61
87 GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
88 const std::string& new_base_url = "https://bar.com/"; 62 const std::string& new_base_url = "https://bar.com/";
89 SetDefaultSearchProvider(new_base_url); 63 SetDefaultSearchProvider(new_base_url);
90 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
91 EXPECT_NE(ntp_url, new_ntp_url);
92 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true));
93 } 64 }
94 65
95 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) { 66 TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) {
96 EXPECT_CALL(*instant_service_observer_.get(), GoogleURLUpdated()).Times(1); 67 EXPECT_CALL(*instant_service_observer_.get(), GoogleURLUpdated()).Times(1);
97 EXPECT_CALL(*instant_ntp_contents_observer_.get(),
98 WebContentsDestroyed(instant_service_->GetNTPContents()))
99 .Times(1);
100 68
101 GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
102 const std::string& new_base_url = "https://www.google.es/"; 69 const std::string& new_base_url = "https://www.google.es/";
103 NotifyGoogleBaseURLUpdate(new_base_url); 70 NotifyGoogleBaseURLUpdate(new_base_url);
104 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
105 EXPECT_NE(ntp_url, new_ntp_url);
106 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true));
107 } 71 }
108 72
109 TEST_F(InstantServiceTest, SendsSearchURLsToRenderer) { 73 TEST_F(InstantServiceTest, SendsSearchURLsToRenderer) {
110 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", 74 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch",
111 "Group1 use_cacheable_ntp:1")); 75 "Group1 use_cacheable_ntp:1"));
112 scoped_ptr<content::MockRenderProcessHost> rph( 76 scoped_ptr<content::MockRenderProcessHost> rph(
113 new content::MockRenderProcessHost(profile())); 77 new content::MockRenderProcessHost(profile()));
114 rph->sink().ClearMessages(); 78 rph->sink().ClearMessages();
115 instant_service_->Observe( 79 instant_service_->Observe(
116 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 80 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 EXPECT_CALL(*instant_service_observer_.get(), GoogleURLUpdated()).Times(1); 132 EXPECT_CALL(*instant_service_observer_.get(), GoogleURLUpdated()).Times(1);
169 133
170 SetDefaultSearchProvider("https://google.com/"); 134 SetDefaultSearchProvider("https://google.com/");
171 InstantSearchPrerenderer* old_prerenderer = GetInstantSearchPrerenderer(); 135 InstantSearchPrerenderer* old_prerenderer = GetInstantSearchPrerenderer();
172 EXPECT_NE(static_cast<InstantSearchPrerenderer*>(NULL), old_prerenderer); 136 EXPECT_NE(static_cast<InstantSearchPrerenderer*>(NULL), old_prerenderer);
173 137
174 const std::string& new_base_url = "https://www.google.es/"; 138 const std::string& new_base_url = "https://www.google.es/";
175 NotifyGoogleBaseURLUpdate(new_base_url); 139 NotifyGoogleBaseURLUpdate(new_base_url);
176 EXPECT_NE(old_prerenderer, GetInstantSearchPrerenderer()); 140 EXPECT_NE(old_prerenderer, GetInstantSearchPrerenderer());
177 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698