| OLD | NEW |
| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 protected: | 45 protected: |
| 46 friend class InstantServiceTest; | 46 friend class InstantServiceTest; |
| 47 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, | 47 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, |
| 48 DispatchDefaultSearchProviderChanged); | 48 DispatchDefaultSearchProviderChanged); |
| 49 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated); | 49 FRIEND_TEST_ALL_PREFIXES(InstantServiceTest, DispatchGoogleURLUpdated); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class InstantServiceTest : public InstantUnitTestBase { | 52 class InstantServiceTest : public InstantUnitTestBase { |
| 53 protected: | 53 protected: |
| 54 virtual void SetUp() OVERRIDE { | 54 virtual void SetUp() OVERRIDE { |
| 55 InstantUnitTestBase::SetUp(); | 55 InstantUnitTestBase::SetUpWithoutCacheableNTP(); |
| 56 field_trial_list_.reset(new base::FieldTrialList( | |
| 57 new metrics::SHA1EntropyProvider("42"))); | |
| 58 | 56 |
| 59 instant_service_observer_.reset(new MockInstantServiceObserver()); | 57 instant_service_observer_.reset(new MockInstantServiceObserver()); |
| 60 instant_service_->AddObserver(instant_service_observer_.get()); | 58 instant_service_->AddObserver(instant_service_observer_.get()); |
| 61 | 59 |
| 62 instant_ntp_contents_observer_.reset(new MockWebContentsObserver()); | 60 instant_ntp_contents_observer_.reset(new MockWebContentsObserver()); |
| 63 instant_ntp_contents_observer_->Observe_( | 61 instant_ntp_contents_observer_->Observe_( |
| 64 instant_service_->GetNTPContents()); | 62 instant_service_->GetNTPContents()); |
| 65 } | 63 } |
| 66 | 64 |
| 67 virtual void TearDown() OVERRIDE { | 65 virtual void TearDown() OVERRIDE { |
| 68 instant_service_->RemoveObserver(instant_service_observer_.get()); | 66 instant_service_->RemoveObserver(instant_service_observer_.get()); |
| 69 instant_ntp_contents_observer_->Observe_(NULL); | 67 instant_ntp_contents_observer_->Observe_(NULL); |
| 70 InstantUnitTestBase::TearDown(); | 68 InstantUnitTestBase::TearDown(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; | 71 scoped_ptr<MockInstantServiceObserver> instant_service_observer_; |
| 74 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_; | 72 scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_; |
| 75 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 76 }; | 73 }; |
| 77 | 74 |
| 78 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) { | 75 TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) { |
| 79 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) | 76 EXPECT_CALL(*instant_service_observer_.get(), DefaultSearchProviderChanged()) |
| 80 .Times(1); | 77 .Times(1); |
| 81 EXPECT_CALL(*instant_ntp_contents_observer_.get(), | 78 EXPECT_CALL(*instant_ntp_contents_observer_.get(), |
| 82 WebContentsDestroyed(instant_service_->GetNTPContents())) | 79 WebContentsDestroyed(instant_service_->GetNTPContents())) |
| 83 .Times(1); | 80 .Times(1); |
| 84 | 81 |
| 85 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); | 82 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 | 95 |
| 99 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); | 96 GURL ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| 100 const std::string& new_base_url = "https://www.google.es/"; | 97 const std::string& new_base_url = "https://www.google.es/"; |
| 101 NotifyGoogleBaseURLUpdate(new_base_url); | 98 NotifyGoogleBaseURLUpdate(new_base_url); |
| 102 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); | 99 GURL new_ntp_url = instant_service_->GetNTPContents()->GetURL(); |
| 103 EXPECT_NE(ntp_url, new_ntp_url); | 100 EXPECT_NE(ntp_url, new_ntp_url); |
| 104 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true)); | 101 EXPECT_TRUE(StartsWithASCII(new_ntp_url.spec(), new_base_url, true)); |
| 105 } | 102 } |
| 106 | 103 |
| 107 TEST_F(InstantServiceTest, SendsSearchURLsToRenderer) { | 104 TEST_F(InstantServiceTest, SendsSearchURLsToRenderer) { |
| 108 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("InstantExtended", | 105 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("EmbeddedSearch", |
| 109 "Group1 use_cacheable_ntp:1")); | 106 "Group1 use_cacheable_ntp:1")); |
| 110 scoped_ptr<content::MockRenderProcessHost> rph( | 107 scoped_ptr<content::MockRenderProcessHost> rph( |
| 111 new content::MockRenderProcessHost(profile())); | 108 new content::MockRenderProcessHost(profile())); |
| 112 rph->sink().ClearMessages(); | 109 rph->sink().ClearMessages(); |
| 113 instant_service_->Observe( | 110 instant_service_->Observe( |
| 114 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 111 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 115 content::Source<content::MockRenderProcessHost>(rph.get()), | 112 content::Source<content::MockRenderProcessHost>(rph.get()), |
| 116 content::NotificationService::NoDetails()); | 113 content::NotificationService::NoDetails()); |
| 117 EXPECT_EQ(1U, rph->sink().message_count()); | 114 EXPECT_EQ(1U, rph->sink().message_count()); |
| 118 const IPC::Message* msg = rph->sink().GetMessageAt(0); | 115 const IPC::Message* msg = rph->sink().GetMessageAt(0); |
| 119 ASSERT_TRUE(msg); | 116 ASSERT_TRUE(msg); |
| 120 std::vector<GURL> search_urls; | 117 std::vector<GURL> search_urls; |
| 121 GURL new_tab_page_url; | 118 GURL new_tab_page_url; |
| 122 ChromeViewMsg_SetSearchURLs::Read(msg, &search_urls, &new_tab_page_url); | 119 ChromeViewMsg_SetSearchURLs::Read(msg, &search_urls, &new_tab_page_url); |
| 123 EXPECT_EQ(2U, search_urls.size()); | 120 EXPECT_EQ(2U, search_urls.size()); |
| 124 EXPECT_EQ("https://www.google.com/alt#quux=", search_urls[0].spec()); | 121 EXPECT_EQ("https://www.google.com/alt#quux=", search_urls[0].spec()); |
| 125 EXPECT_EQ("https://www.google.com/url?bar=", search_urls[1].spec()); | 122 EXPECT_EQ("https://www.google.com/url?bar=", search_urls[1].spec()); |
| 126 EXPECT_EQ("https://www.google.com/newtab", new_tab_page_url.spec()); | 123 EXPECT_EQ("https://www.google.com/newtab", new_tab_page_url.spec()); |
| 127 } | 124 } |
| OLD | NEW |