| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/service/cloud_print/connector_settings.h" | 5 #include "chrome/service/cloud_print/connector_settings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/common/cloud_print/cloud_print_constants.h" | 15 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 15 #include "chrome/service/service_process_prefs.h" | 16 #include "chrome/service/service_process_prefs.h" |
| 16 | 17 |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace cloud_print { | 21 namespace cloud_print { |
| 21 | 22 |
| 22 const char kServiceStateContent[] = | 23 const char kServiceStateContent[] = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 " 'delete_on_enum_fail' : true" | 44 " 'delete_on_enum_fail' : true" |
| 44 " }" | 45 " }" |
| 45 " }" | 46 " }" |
| 46 "}"; | 47 "}"; |
| 47 | 48 |
| 48 | 49 |
| 49 class ConnectorSettingsTest : public testing::Test { | 50 class ConnectorSettingsTest : public testing::Test { |
| 50 protected: | 51 protected: |
| 51 void SetUp() override { | 52 void SetUp() override { |
| 52 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 53 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 53 message_loop_proxy_ = base::MessageLoopProxy::current(); | 54 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 ServiceProcessPrefs* CreateTestFile(const char* json) { | 57 ServiceProcessPrefs* CreateTestFile(const char* json) { |
| 57 base::FilePath file_name = temp_dir_.path().AppendASCII("file.txt"); | 58 base::FilePath file_name = temp_dir_.path().AppendASCII("file.txt"); |
| 58 base::DeleteFile(file_name, false); | 59 base::DeleteFile(file_name, false); |
| 59 if (json) { | 60 if (json) { |
| 60 std::string content = json; | 61 std::string content = json; |
| 61 std::replace(content.begin(), content.end(), '\'', '"'); | 62 std::replace(content.begin(), content.end(), '\'', '"'); |
| 62 base::WriteFile(file_name, content.c_str(), content.size()); | 63 base::WriteFile(file_name, content.c_str(), content.size()); |
| 63 } | 64 } |
| 64 ServiceProcessPrefs* prefs = | 65 ServiceProcessPrefs* prefs = |
| 65 new ServiceProcessPrefs(file_name, message_loop_proxy_.get()); | 66 new ServiceProcessPrefs(file_name, task_runner_.get()); |
| 66 prefs->ReadPrefs(); | 67 prefs->ReadPrefs(); |
| 67 return prefs; | 68 return prefs; |
| 68 } | 69 } |
| 69 | 70 |
| 70 base::ScopedTempDir temp_dir_; | 71 base::ScopedTempDir temp_dir_; |
| 71 base::MessageLoop message_loop_; | 72 base::MessageLoop message_loop_; |
| 72 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 TEST_F(ConnectorSettingsTest, InitFromEmpty) { | 76 TEST_F(ConnectorSettingsTest, InitFromEmpty) { |
| 76 const char* const kEmptyJSons[] = { | 77 const char* const kEmptyJSons[] = { |
| 77 NULL, | 78 NULL, |
| 78 "{}", | 79 "{}", |
| 79 "{'foo': []}", | 80 "{'foo': []}", |
| 80 "{'foo',,}", | 81 "{'foo',,}", |
| 81 }; | 82 }; |
| 82 for (size_t i = 0; i < arraysize(kEmptyJSons); ++i) { | 83 for (size_t i = 0; i < arraysize(kEmptyJSons); ++i) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 settings.SetXmppPingTimeoutSec(256); | 143 settings.SetXmppPingTimeoutSec(256); |
| 143 EXPECT_TRUE(settings.xmpp_ping_enabled()); | 144 EXPECT_TRUE(settings.xmpp_ping_enabled()); |
| 144 EXPECT_EQ(settings.xmpp_ping_timeout_sec(), 256); | 145 EXPECT_EQ(settings.xmpp_ping_timeout_sec(), 256); |
| 145 | 146 |
| 146 // Set invalid settings, and check correct defaults. | 147 // Set invalid settings, and check correct defaults. |
| 147 settings.SetXmppPingTimeoutSec(1); | 148 settings.SetXmppPingTimeoutSec(1); |
| 148 EXPECT_EQ(settings.xmpp_ping_timeout_sec(), kMinXmppPingTimeoutSecs); | 149 EXPECT_EQ(settings.xmpp_ping_timeout_sec(), kMinXmppPingTimeoutSecs); |
| 149 } | 150 } |
| 150 | 151 |
| 151 } // namespace cloud_print | 152 } // namespace cloud_print |
| OLD | NEW |