OLD | NEW |
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 <utility> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
11 #include "components/browser_sync/common/browser_sync_switches.h" | 13 #include "components/browser_sync/common/browser_sync_switches.h" |
12 #include "components/sync_driver/about_sync_util.h" | 14 #include "components/sync_driver/about_sync_util.h" |
13 #include "components/sync_driver/sync_service.h" | 15 #include "components/sync_driver/sync_service.h" |
14 #include "content/public/browser/site_instance.h" | 16 #include "content/public/browser/site_instance.h" |
15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "content/public/test/test_web_ui.h" | 19 #include "content/public/test/test_web_ui.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 class TestableSyncInternalsMessageHandler : public SyncInternalsMessageHandler { | 24 class TestableSyncInternalsMessageHandler : public SyncInternalsMessageHandler { |
23 public: | 25 public: |
24 explicit TestableSyncInternalsMessageHandler( | 26 explicit TestableSyncInternalsMessageHandler( |
25 content::WebUI* web_ui, | 27 content::WebUI* web_ui, |
26 scoped_ptr<AboutSyncDataExtractor> about_sync_data_extractor) | 28 scoped_ptr<AboutSyncDataExtractor> about_sync_data_extractor) |
27 : SyncInternalsMessageHandler(about_sync_data_extractor.Pass()) { | 29 : SyncInternalsMessageHandler(std::move(about_sync_data_extractor)) { |
28 set_web_ui(web_ui); | 30 set_web_ui(web_ui); |
29 } | 31 } |
30 }; | 32 }; |
31 | 33 |
32 class FakeExtractor : public AboutSyncDataExtractor { | 34 class FakeExtractor : public AboutSyncDataExtractor { |
33 public: | 35 public: |
34 scoped_ptr<base::DictionaryValue> ConstructAboutInformation( | 36 scoped_ptr<base::DictionaryValue> ConstructAboutInformation( |
35 sync_driver::SyncService* service, | 37 sync_driver::SyncService* service, |
36 SigninManagerBase* signin) override { | 38 SigninManagerBase* signin) override { |
37 call_count_++; | 39 call_count_++; |
38 last_service_ = service; | 40 last_service_ = service; |
39 last_signin_ = signin; | 41 last_signin_ = signin; |
40 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); | 42 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); |
41 dictionary->SetString("fake_key", "fake_value"); | 43 dictionary->SetString("fake_key", "fake_value"); |
42 return dictionary.Pass(); | 44 return dictionary; |
43 } | 45 } |
44 | 46 |
45 int call_count() const { return call_count_; } | 47 int call_count() const { return call_count_; } |
46 sync_driver::SyncService* last_service() const { return last_service_; } | 48 sync_driver::SyncService* last_service() const { return last_service_; } |
47 SigninManagerBase* last_signin() const { return last_signin_; } | 49 SigninManagerBase* last_signin() const { return last_signin_; } |
48 | 50 |
49 private: | 51 private: |
50 int call_count_ = 0; | 52 int call_count_ = 0; |
51 sync_driver::SyncService* last_service_ = nullptr; | 53 sync_driver::SyncService* last_service_ = nullptr; |
52 SigninManagerBase* last_signin_ = nullptr; | 54 SigninManagerBase* last_signin_ = nullptr; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } | 121 } |
120 | 122 |
121 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithoutService) { | 123 TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoWithoutService) { |
122 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); | 124 base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); |
123 handler()->OnStateChanged(); | 125 handler()->OnStateChanged(); |
124 EXPECT_EQ(1, fake_extractor()->call_count()); | 126 EXPECT_EQ(1, fake_extractor()->call_count()); |
125 EXPECT_EQ(nullptr, fake_extractor()->last_service()); | 127 EXPECT_EQ(nullptr, fake_extractor()->last_service()); |
126 EXPECT_EQ(nullptr, fake_extractor()->last_signin()); | 128 EXPECT_EQ(nullptr, fake_extractor()->last_signin()); |
127 ValidateAboutInfoCall(); | 129 ValidateAboutInfoCall(); |
128 } | 130 } |
OLD | NEW |