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

Side by Side Diff: components/gcm_driver/instance_id/instance_id_driver_unittest.cc

Issue 2846723005: Use ScopedTaskEnvironment instead of MessageLoopForUI in components tests. (Closed)
Patch Set: self-review 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 "components/gcm_driver/instance_id/instance_id_driver.h" 5 #include "components/gcm_driver/instance_id/instance_id_driver.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 13 #include "base/run_loop.h"
15 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/test/scoped_task_environment.h"
16 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h" 16 #include "components/gcm_driver/instance_id/fake_gcm_driver_for_instance_id.h"
17 #include "components/gcm_driver/instance_id/instance_id.h" 17 #include "components/gcm_driver/instance_id/instance_id.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 #if defined(OS_ANDROID) 20 #if defined(OS_ANDROID)
21 #include "components/gcm_driver/instance_id/instance_id_android.h" 21 #include "components/gcm_driver/instance_id/instance_id_android.h"
22 #include "components/gcm_driver/instance_id/scoped_use_fake_instance_id_android. h" 22 #include "components/gcm_driver/instance_id/scoped_use_fake_instance_id_android. h"
23 #endif // OS_ANDROID 23 #endif // OS_ANDROID
24 24
25 namespace instance_id { 25 namespace instance_id {
(...skipping 19 matching lines...) Expand all
45 ch != '_' && ch != '-') 45 ch != '_' && ch != '-')
46 return false; 46 return false;
47 } 47 }
48 return true; 48 return true;
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 class InstanceIDDriverTest : public testing::Test { 53 class InstanceIDDriverTest : public testing::Test {
54 public: 54 public:
55 InstanceIDDriverTest(); 55 InstanceIDDriverTest()
56 : scoped_task_environment_(
57 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
56 ~InstanceIDDriverTest() override; 58 ~InstanceIDDriverTest() override;
57 59
58 // testing::Test: 60 // testing::Test:
59 void SetUp() override; 61 void SetUp() override;
60 void TearDown() override; 62 void TearDown() override;
61 63
62 void WaitForAsyncOperation(); 64 void WaitForAsyncOperation();
63 65
64 // Recreates InstanceIDDriver to simulate restart. 66 // Recreates InstanceIDDriver to simulate restart.
65 void RecreateInstanceIDDriver(); 67 void RecreateInstanceIDDriver();
(...skipping 14 matching lines...) Expand all
80 82
81 InstanceIDDriver* driver() const { return driver_.get(); } 83 InstanceIDDriver* driver() const { return driver_.get(); }
82 84
83 private: 85 private:
84 void GetIDCompleted(const std::string& id); 86 void GetIDCompleted(const std::string& id);
85 void GetCreationTimeCompleted(const base::Time& creation_time); 87 void GetCreationTimeCompleted(const base::Time& creation_time);
86 void DeleteIDCompleted(InstanceID::Result result); 88 void DeleteIDCompleted(InstanceID::Result result);
87 void GetTokenCompleted(const std::string& token, InstanceID::Result result); 89 void GetTokenCompleted(const std::string& token, InstanceID::Result result);
88 void DeleteTokenCompleted(InstanceID::Result result); 90 void DeleteTokenCompleted(InstanceID::Result result);
89 91
90 base::MessageLoopForUI message_loop_; 92 base::test::ScopedTaskEnvironment scoped_task_environment_;
91 std::unique_ptr<FakeGCMDriverForInstanceID> gcm_driver_; 93 std::unique_ptr<FakeGCMDriverForInstanceID> gcm_driver_;
92 std::unique_ptr<InstanceIDDriver> driver_; 94 std::unique_ptr<InstanceIDDriver> driver_;
93 95
94 #if defined(OS_ANDROID) 96 #if defined(OS_ANDROID)
95 InstanceIDAndroid::ScopedBlockOnAsyncTasksForTesting block_async_; 97 InstanceIDAndroid::ScopedBlockOnAsyncTasksForTesting block_async_;
96 ScopedUseFakeInstanceIDAndroid use_fake_; 98 ScopedUseFakeInstanceIDAndroid use_fake_;
97 #endif // OS_ANDROID 99 #endif // OS_ANDROID
98 100
99 std::string id_; 101 std::string id_;
100 base::Time creation_time_; 102 base::Time creation_time_;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 GetToken(instance_id, kAuthorizedEntity1, kScope2, options); 372 GetToken(instance_id, kAuthorizedEntity1, kScope2, options);
371 EXPECT_FALSE(new_token1.empty()); 373 EXPECT_FALSE(new_token1.empty());
372 EXPECT_NE(token1, new_token1); 374 EXPECT_NE(token1, new_token1);
373 375
374 // The other token is not affected by the deletion. 376 // The other token is not affected by the deletion.
375 EXPECT_EQ(token2, 377 EXPECT_EQ(token2,
376 GetToken(instance_id, kAuthorizedEntity2, kScope1, options)); 378 GetToken(instance_id, kAuthorizedEntity2, kScope1, options));
377 } 379 }
378 380
379 } // namespace instance_id 381 } // namespace instance_id
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698