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

Side by Side Diff: chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc

Issue 2872023002: [Sync] Add a simple UI to sync-internals to create UserEvents. (Closed)
Patch Set: Fixed unittests. Created 3 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ui/webui/sync_internals_message_handler.h" 5 #include "chrome/browser/ui/webui/sync_internals_message_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
22 namespace { 22 namespace {
23 23
24 class TestableSyncInternalsMessageHandler : public SyncInternalsMessageHandler { 24 class TestableSyncInternalsMessageHandler : public SyncInternalsMessageHandler {
25 public: 25 public:
26 explicit TestableSyncInternalsMessageHandler( 26 explicit TestableSyncInternalsMessageHandler(
27 content::WebUI* web_ui, 27 content::WebUI* web_ui,
28 std::unique_ptr<AboutSyncDataExtractor> about_sync_data_extractor) 28 std::unique_ptr<AboutSyncDataExtractor> about_sync_data_extractor)
29 : SyncInternalsMessageHandler(std::move(about_sync_data_extractor)) { 29 : SyncInternalsMessageHandler(std::move(about_sync_data_extractor)) {
30 set_web_ui(web_ui); 30 set_web_ui(web_ui);
31 } 31 }
32
33 void SignalIsInitialized() { AllowJavascript(); }
32 }; 34 };
33 35
34 class FakeExtractor : public AboutSyncDataExtractor { 36 class FakeExtractor : public AboutSyncDataExtractor {
35 public: 37 public:
36 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( 38 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
37 syncer::SyncService* service, 39 syncer::SyncService* service,
38 SigninManagerBase* signin) override { 40 SigninManagerBase* signin) override {
39 call_count_++; 41 call_count_++;
40 last_service_ = service; 42 last_service_ = service;
41 last_signin_ = signin; 43 last_signin_ = signin;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ASSERT_TRUE(arg2); 88 ASSERT_TRUE(arg2);
87 89
88 const base::DictionaryValue* root_dictionary = nullptr; 90 const base::DictionaryValue* root_dictionary = nullptr;
89 ASSERT_TRUE(arg2->GetAsDictionary(&root_dictionary)); 91 ASSERT_TRUE(arg2->GetAsDictionary(&root_dictionary));
90 92
91 std::string fake_value; 93 std::string fake_value;
92 EXPECT_TRUE(root_dictionary->GetString("fake_key", &fake_value)); 94 EXPECT_TRUE(root_dictionary->GetString("fake_key", &fake_value));
93 EXPECT_EQ("fake_value", fake_value); 95 EXPECT_EQ("fake_value", fake_value);
94 } 96 }
95 97
96 SyncInternalsMessageHandler* handler() { return handler_.get(); } 98 void ValidateEmptyAboutInfoCall() {
99 EXPECT_TRUE(web_ui_.call_data().empty());
100 }
101
102 TestableSyncInternalsMessageHandler* handler() { return handler_.get(); }
97 FakeExtractor* fake_extractor() { return fake_extractor_; } 103 FakeExtractor* fake_extractor() { return fake_extractor_; }
98 104
99 private: 105 private:
100 content::TestBrowserThreadBundle thread_bundle_; 106 content::TestBrowserThreadBundle thread_bundle_;
101 TestingProfile profile_; 107 TestingProfile profile_;
102 content::TestWebUI web_ui_; 108 content::TestWebUI web_ui_;
103 scoped_refptr<content::SiteInstance> site_instance_; 109 scoped_refptr<content::SiteInstance> site_instance_;
104 std::unique_ptr<content::WebContents> web_contents_; 110 std::unique_ptr<content::WebContents> web_contents_;
105 std::unique_ptr<SyncInternalsMessageHandler> handler_; 111 std::unique_ptr<TestableSyncInternalsMessageHandler> handler_;
106 112
107 // Non-owning pointer to the about information the handler uses. This 113 // Non-owning pointer to the about information the handler uses. This
108 // extractor is owned by the handler. 114 // extractor is owned by the handler.
109 FakeExtractor* fake_extractor_; 115 FakeExtractor* fake_extractor_;
110 }; 116 };
111 117
112 } // namespace 118 } // namespace
113 119
120 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoBeforeInitialized) {
121 handler()->OnStateChanged(nullptr);
122 ValidateEmptyAboutInfoCall();
123 }
124
114 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithService) { 125 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithService) {
126 handler()->SignalIsInitialized();
115 handler()->OnStateChanged(nullptr); 127 handler()->OnStateChanged(nullptr);
116 EXPECT_EQ(1, fake_extractor()->call_count()); 128 EXPECT_EQ(1, fake_extractor()->call_count());
117 EXPECT_NE(nullptr, fake_extractor()->last_service()); 129 EXPECT_NE(nullptr, fake_extractor()->last_service());
118 EXPECT_NE(nullptr, fake_extractor()->last_signin()); 130 EXPECT_NE(nullptr, fake_extractor()->last_signin());
119 ValidateAboutInfoCall(); 131 ValidateAboutInfoCall();
120 } 132 }
121 133
122 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithoutService) { 134 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithoutService) {
123 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); 135 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync);
136 handler()->SignalIsInitialized();
124 handler()->OnStateChanged(nullptr); 137 handler()->OnStateChanged(nullptr);
125 EXPECT_EQ(1, fake_extractor()->call_count()); 138 EXPECT_EQ(1, fake_extractor()->call_count());
126 EXPECT_EQ(nullptr, fake_extractor()->last_service()); 139 EXPECT_EQ(nullptr, fake_extractor()->last_service());
127 EXPECT_EQ(nullptr, fake_extractor()->last_signin()); 140 EXPECT_EQ(nullptr, fake_extractor()->last_signin());
128 ValidateAboutInfoCall(); 141 ValidateAboutInfoCall();
129 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698