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

Side by Side Diff: chrome/browser/chromeos/policy/server_backed_state_keys_broker_unittest.cc

Issue 2657013002: Introduce ThreadTaskRunnerHandle::OverrideForTesting and TestMockTimeTaskRunner::ScopedContext. (Closed)
Patch Set: review:xunjeli#33 Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/policy/server_backed_state_keys_broker.h" 5 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 base::Unretained(this))); 106 base::Unretained(this)));
107 base::RunLoop().RunUntilIdle(); 107 base::RunLoop().RunUntilIdle();
108 EXPECT_TRUE(updated_); 108 EXPECT_TRUE(updated_);
109 ExpectGood(); 109 ExpectGood();
110 110
111 // Update callbacks get fired if the keys change. 111 // Update callbacks get fired if the keys change.
112 state_keys_.erase(state_keys_.begin()); 112 state_keys_.erase(state_keys_.begin());
113 state_keys_.push_back("4"); 113 state_keys_.push_back("4");
114 fake_session_manager_client_.set_server_backed_state_keys(state_keys_); 114 fake_session_manager_client_.set_server_backed_state_keys(state_keys_);
115 updated_ = false; 115 updated_ = false;
116 task_runner_->RunPendingTasks(); 116 task_runner_->RunUntilIdle();
117 base::RunLoop().RunUntilIdle();
118 EXPECT_TRUE(updated_); 117 EXPECT_TRUE(updated_);
119 ExpectGood(); 118 ExpectGood();
120 119
121 // No update callback if the keys are unchanged. 120 // No update callback if the keys are unchanged.
122 updated_ = false; 121 updated_ = false;
123 task_runner_->RunPendingTasks(); 122 task_runner_->RunUntilIdle();
124 base::RunLoop().RunUntilIdle();
125 EXPECT_FALSE(updated_); 123 EXPECT_FALSE(updated_);
126 ExpectGood(); 124 ExpectGood();
127 } 125 }
128 126
129 TEST_F(ServerBackedStateKeysBrokerTest, Request) { 127 TEST_F(ServerBackedStateKeysBrokerTest, Request) {
130 broker_.RequestStateKeys( 128 broker_.RequestStateKeys(
131 base::Bind(&ServerBackedStateKeysBrokerTest::HandleStateKeysCallback, 129 base::Bind(&ServerBackedStateKeysBrokerTest::HandleStateKeysCallback,
132 base::Unretained(this))); 130 base::Unretained(this)));
133 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
134 ExpectGood(); 132 ExpectGood();
135 EXPECT_TRUE(callback_invoked_); 133 EXPECT_TRUE(callback_invoked_);
136 EXPECT_EQ(state_keys_, callback_state_keys_); 134 EXPECT_EQ(state_keys_, callback_state_keys_);
137 } 135 }
138 136
139 TEST_F(ServerBackedStateKeysBrokerTest, RequestFailure) { 137 TEST_F(ServerBackedStateKeysBrokerTest, RequestFailure) {
140 fake_session_manager_client_.set_server_backed_state_keys( 138 fake_session_manager_client_.set_server_backed_state_keys(
141 std::vector<std::string>()); 139 std::vector<std::string>());
142 140
143 broker_.RequestStateKeys( 141 broker_.RequestStateKeys(
144 base::Bind(&ServerBackedStateKeysBrokerTest::HandleStateKeysCallback, 142 base::Bind(&ServerBackedStateKeysBrokerTest::HandleStateKeysCallback,
145 base::Unretained(this))); 143 base::Unretained(this)));
146 base::RunLoop().RunUntilIdle(); 144 base::RunLoop().RunUntilIdle();
147 EXPECT_TRUE(callback_invoked_); 145 EXPECT_TRUE(callback_invoked_);
148 EXPECT_TRUE(callback_state_keys_.empty()); 146 EXPECT_TRUE(callback_state_keys_.empty());
149 } 147 }
150 148
151 } // namespace policy 149 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698