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

Unified 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: Added ui and unit tests Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/search/instant_service_unittest.cc
diff --git a/chrome/browser/search/instant_service_unittest.cc b/chrome/browser/search/instant_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d072346987a1b3946cc1cb64a86cabd468fd11a6
--- /dev/null
+++ b/chrome/browser/search/instant_service_unittest.cc
@@ -0,0 +1,116 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_samples.h"
+#include "base/metrics/statistics_recorder.h"
+#include "base/values.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/google/google_url_tracker.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search/instant_service.h"
+#include "chrome/browser/search/instant_service_factory.h"
+#include "chrome/browser/search/instant_service_observer.h"
+#include "chrome/browser/search/search.h"
+#include "chrome/browser/search/search_test_utils.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/common/instant_types.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/browser_with_test_window_test.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chrome {
samarth 2013/08/02 21:51:15 Why is this in namespace chrome? InstantService is
Anuj 2013/08/09 07:22:00 Done.
+using base::HistogramBase;
samarth 2013/08/02 21:51:15 nit: add an empty line above
Anuj 2013/08/09 07:22:00 Done.
+using base::HistogramSamples;
+using base::StatisticsRecorder;
+using testing::_;
+
+class MockInstantServiceObserver : public InstantServiceObserver {
+ public:
+ MOCK_METHOD1(ThemeInfoChanged, void(const ThemeBackgroundInfo&));
+ MOCK_METHOD1(MostVisitedItemsChanged,
+ void(const std::vector<InstantMostVisitedItem>&));
+ MOCK_METHOD0(DefaultSearchProviderChanged, void());
+ MOCK_METHOD0(GoogleURLUpdated, void());
+};
+
+class MockWebContentsObserver : public content::WebContentsObserver {
+ public:
+ MOCK_METHOD1(WebContentsDestroyed, void(content::WebContents*));
+
+ protected:
+ friend class InstantServiceTest;
+};
+
+class InstantServiceTest : public BrowserWithTestWindowTest {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ EnableInstantExtendedAPIForTesting();
+ BrowserWithTestWindowTest::SetUp();
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile(), &TemplateURLServiceFactory::BuildInstanceFor);
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile());
+ ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service);
+ instant_service_ = InstantServiceFactory::GetForProfile(profile());
+ instant_service_observer_.reset(new MockInstantServiceObserver());
+ instant_ntp_contents_observer_.reset(new MockWebContentsObserver());
+ instant_service_->AddObserver(instant_service_observer());
+ instant_ntp_contents_observer()->Observe(
+ instant_service_->GetNTPContents());
+ }
+
+ MockInstantServiceObserver* instant_service_observer() {
+ return instant_service_observer_.get();
+ }
+
+ MockWebContentsObserver* instant_ntp_contents_observer() {
+ return instant_ntp_contents_observer_.get();
+ }
+
+ InstantService* instant_service_;
+ scoped_ptr<MockInstantServiceObserver> instant_service_observer_;
+ scoped_ptr<MockWebContentsObserver> instant_ntp_contents_observer_;
+};
+
+TEST_F(InstantServiceTest, DispatchDefaultSearchProviderChanged) {
+ EXPECT_CALL(*instant_service_observer(), DefaultSearchProviderChanged())
+ .Times(1);
+ EXPECT_CALL(*instant_ntp_contents_observer(),
+ WebContentsDestroyed(instant_service_->GetNTPContents()))
+ .Times(1);
+
+ search_test_utils::SetSearchProvider(profile());
+}
+
+TEST_F(InstantServiceTest, DispatchGoogleURLUpdated) {
+ TestingPrefServiceSyncable* service = profile()->GetTestingPrefService();
+ service->SetUserPref(prefs::kLastPromptedGoogleURL,
+ new base::StringValue("https://www.google.com/"));
+ EXPECT_CALL(*instant_service_observer(), GoogleURLUpdated()).Times(1);
+ EXPECT_CALL(*instant_ntp_contents_observer(),
+ WebContentsDestroyed(instant_service_->GetNTPContents()))
+ .Times(1);
+
+ GoogleURLTracker::UpdatedDetails details(GURL("https://www.google.com/"),
+ GURL("https://www.google.es/"));
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
+ content::Source<Profile>(profile()->GetOriginalProfile()),
+ content::Details<GoogleURLTracker::UpdatedDetails>(&details));
+}
+} // namespace chrome
samarth 2013/08/02 21:51:15 nit: add an empty line above
Anuj 2013/08/09 07:22:00 Done.

Powered by Google App Engine
This is Rietveld 408576698