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

Side by Side Diff: chrome/service/cloud_print/connector_settings_unittest.cc

Issue 11027070: Moved JsonPrefStore to use SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/service/service_process_prefs.h" 15 #include "chrome/service/service_process_prefs.h"
15 16
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 const char kServiceStateContent[] = 20 const char kServiceStateContent[] =
20 "{" 21 "{"
21 " 'cloud_print': {" 22 " 'cloud_print': {"
(...skipping 12 matching lines...) Expand all
34 " ]," 35 " ],"
35 " 'print_system_settings': {" 36 " 'print_system_settings': {"
36 " 'delete_on_enum_fail' : true" 37 " 'delete_on_enum_fail' : true"
37 " }" 38 " }"
38 " }" 39 " }"
39 "}"; 40 "}";
40 41
41 42
42 class ConnectorSettingsTest : public testing::Test { 43 class ConnectorSettingsTest : public testing::Test {
43 protected: 44 protected:
44 virtual void SetUp() { 45 virtual void SetUp() OVERRIDE {
45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
47 blocking_pool_ = new base::SequencedWorkerPool(1, "TestBlocking");
46 message_loop_proxy_ = base::MessageLoopProxy::current(); 48 message_loop_proxy_ = base::MessageLoopProxy::current();
47 } 49 }
48 50
51 virtual void TearDown() OVERRIDE {
52 blocking_pool_->Shutdown();
53 }
54
49 ServiceProcessPrefs* CreateTestFile(const char* json) { 55 ServiceProcessPrefs* CreateTestFile(const char* json) {
50 FilePath file_name = temp_dir_.path().AppendASCII("file.txt"); 56 FilePath file_name = temp_dir_.path().AppendASCII("file.txt");
51 file_util::Delete(file_name, false); 57 file_util::Delete(file_name, false);
52 if (json) { 58 if (json) {
53 std::string content = json; 59 std::string content = json;
54 std::replace(content.begin(), content.end(), '\'', '"'); 60 std::replace(content.begin(), content.end(), '\'', '"');
55 file_util::WriteFile(file_name, content.c_str(), content.size()); 61 file_util::WriteFile(file_name, content.c_str(), content.size());
56 } 62 }
57 ServiceProcessPrefs* prefs = 63 ServiceProcessPrefs* prefs =
58 new ServiceProcessPrefs(file_name, message_loop_proxy_.get()); 64 new ServiceProcessPrefs(file_name, blocking_pool_);
59 prefs->ReadPrefs(); 65 prefs->ReadPrefs();
60 return prefs; 66 return prefs;
61 } 67 }
62 68
63 ScopedTempDir temp_dir_; 69 ScopedTempDir temp_dir_;
64 MessageLoop message_loop_; 70 MessageLoop message_loop_;
65 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 71 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
72 scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
66 }; 73 };
67 74
68 TEST_F(ConnectorSettingsTest, InitFromEmpty) { 75 TEST_F(ConnectorSettingsTest, InitFromEmpty) {
69 const char* const kEmptyJSons[] = { 76 const char* const kEmptyJSons[] = {
70 NULL, 77 NULL,
71 "{}", 78 "{}",
72 "{'foo': []}", 79 "{'foo': []}",
73 "{'foo',,}", 80 "{'foo',,}",
74 }; 81 };
75 for (size_t i = 0; i < arraysize(kEmptyJSons); ++i) { 82 for (size_t i = 0; i < arraysize(kEmptyJSons); ++i) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 118
112 EXPECT_EQ(settings1.server_url(), settings2.server_url()); 119 EXPECT_EQ(settings1.server_url(), settings2.server_url());
113 EXPECT_EQ(settings1.proxy_id(), settings2.proxy_id()); 120 EXPECT_EQ(settings1.proxy_id(), settings2.proxy_id());
114 EXPECT_EQ(settings1.delete_on_enum_fail(), settings2.delete_on_enum_fail()); 121 EXPECT_EQ(settings1.delete_on_enum_fail(), settings2.delete_on_enum_fail());
115 EXPECT_EQ(settings1.print_system_settings()->size(), 122 EXPECT_EQ(settings1.print_system_settings()->size(),
116 settings2.print_system_settings()->size()); 123 settings2.print_system_settings()->size());
117 EXPECT_EQ(settings1.connect_new_printers(), settings2.connect_new_printers()); 124 EXPECT_EQ(settings1.connect_new_printers(), settings2.connect_new_printers());
118 EXPECT_TRUE(settings2.IsPrinterBlacklisted("prn1")); 125 EXPECT_TRUE(settings2.IsPrinterBlacklisted("prn1"));
119 } 126 }
120 127
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698