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

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

Issue 23455047: InstantExtended: Send search URLs to renderers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 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/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "chrome/browser/search/instant_service.h" 11 #include "chrome/browser/search/instant_service.h"
11 #include "chrome/browser/search/instant_service_observer.h" 12 #include "chrome/browser/search/instant_service_observer.h"
12 #include "chrome/browser/search/instant_unittest_base.h" 13 #include "chrome/browser/search/instant_unittest_base.h"
13 #include "chrome/browser/search/search.h" 14 #include "chrome/browser/search/search.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/host_desktop.h" 17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/common/render_messages.h"
19 #include "components/variations/entropy_provider.h"
20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
24 #include "content/public/test/mock_render_process_host.h"
25 #include "ipc/ipc_message.h"
26 #include "ipc/ipc_test_sink.h"
19 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
20 28 #include "url/gurl.h"
21 namespace chrome {
22 29
23 namespace { 30 namespace {
24 31
25 class MockInstantServiceObserver : public InstantServiceObserver { 32 class MockInstantServiceObserver : public InstantServiceObserver {
26 public: 33 public:
27 MOCK_METHOD0(DefaultSearchProviderChanged, void()); 34 MOCK_METHOD0(DefaultSearchProviderChanged, void());
28 MOCK_METHOD0(GoogleURLUpdated, void()); 35 MOCK_METHOD0(GoogleURLUpdated, void());
29 }; 36 };
30 37
31 class MockWebContentsObserver : public content::WebContentsObserver { 38 class MockWebContentsObserver : public content::WebContentsObserver {
32 public: 39 public:
33 MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*)); 40 MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*));
34 41
35 // Dumb override to make MSVC happy. 42 // Dumb override to make MSVC happy.
36 void Observe_(content::WebContents* contents) { 43 void Observe_(content::WebContents* contents) {
37 content::WebContentsObserver::Observe(contents); 44 content::WebContentsObserver::Observe(contents);
38 } 45 }
39 46
40 protected: 47 protected:
41 friend class InstantServiceTest; 48 friend class InstantServiceTest;
42 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, 49 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest,
43 DispatchDefaultSearchProviderChanged); 50 DispatchDefaultSearchProviderChanged);
44 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated); 51 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated);
45 }; 52 };
46 53
54 } // namespace
55
47 class InstantServiceTest : public InstantUnitTestBase { 56 class InstantServiceTest : public InstantUnitTestBase {
48 protected: 57 protected:
49 virtual void SetUp() OVERRIDE { 58 virtual void SetUp() OVERRIDE {
50 InstantUnitTestBase::SetUp(); 59 InstantUnitTestBase::SetUp();
60 field_trial_list_.reset(new base::FieldTrialList(
61 new metrics::SHA1EntropyProvider("42")));
51 62
52 instant_service_observer_.reset(new MockInstantServiceObserver()); 63 instant_service_observer_.reset(new MockInstantServiceObserver());
53 instant_service_->AddObserver(instant_service_observer_.get()); 64 instant_service_->AddObserver(instant_service_observer_.get());
54 65
55 instant_ntp_contents_observer_.reset(new MockWebContentsObserver()); 66 instant_ntp_contents_observer_.reset(new MockWebContentsObserver());
56 instant_ntp_contents_observer_->Observe_( 67 instant_ntp_contents_observer_->Observe_(
57 instant_service_->GetNTPContents()); 68 instant_service_->GetNTPContents());
58 } 69 }
59 70
60 virtual void TearDown() OVERRIDE { 71 virtual void TearDown() OVERRIDE {
61 instant_service_->RemoveObserver(instant_service_observer_.get()); 72 instant_service_->RemoveObserver(instant_service_observer_.get());
62 instant_ntp_contents_observer_->Observe_(NULL); 73 instant_ntp_contents_observer_->Observe_(NULL);
63 InstantUnitTestBase::TearDown(); 74 InstantUnitTestBase::TearDown();
64 } 75 }
65 76
66 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; 77 scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
67 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_; 78 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_;
79 scoped_ptr<base::FieldTrialList> field_trial_list_;
68 }; 80 };
69 81
70 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) { 82 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) {
71 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) 83 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged())
72 .Times(1); 84 .Times(1);
73 EXPECT_CALL(*instant_ntp_contents_observer_.get(), 85 EXPECT_CALL(*instant_ntp_contents_observer_.get(),
74 WebContentsDestroyed(instant_service_->GetNTPContents())) 86 WebContentsDestroyed(instant_service_->GetNTPContents()))
75 .Times(1); 87 .Times(1);
76 88
77 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); 89 GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
(...skipping 11 matching lines...) Expand all
89 .Times(1); 101 .Times(1);
90 102
91 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); 103 GURL ntp_url = instant_service_->GetNTPContents()->GetURL();
92 const std::string& new_base_url = "https://www.google.es/"; 104 const std::string& new_base_url = "https://www.google.es/";
93 NotifyGoogleBaseURLUpdate(new_base_url); 105 NotifyGoogleBaseURLUpdate(new_base_url);
94 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); 106 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL();
95 EXPECT_NE(ntp_url, new_ntp_url); 107 EXPECT_NE(ntp_url, new_ntp_url);
96 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true)); 108 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true));
97 } 109 }
98 110
99 } // namespace 111 TEST_F(InstantServiceTest, SendsSearchURLsToRenderer) {
100 112 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended",
101 } // namespace chrome 113 "Group1 use_cacheable_ntp:1"));
114 scoped_ptr<content::MockRenderProcessHost> rph(
115 new content::MockRenderProcessHost(profile()));
116 rph->sink().ClearMessages();
117 instant_service_->Observe(
118 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
119 content::Source<content::MockRenderProcessHost>(rph.get()),
120 content::NotificationService::NoDetails());
121 EXPECT_EQ(1U, rph->sink().message_count());
122 const IPC::Message* msg = rph->sink().GetMessageAt(0);
123 ASSERT_TRUE(msg);
124 std::vector<GURL> search_urls;
125 GURL new_tab_page_url;
126 ChromeViewMsg_SetSearchURLs::Read(msg, &search_urls, &new_tab_page_url);
127 EXPECT_EQ(2U, search_urls.size());
128 EXPECT_EQ("https://www.google.com/alt#quux=", search_urls[0].spec());
129 EXPECT_EQ("https://www.google.com/url?bar=", search_urls[1].spec());
130 EXPECT_EQ("https://www.google.com/newtab", new_tab_page_url.spec());
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698