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

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service_browsertest.cc

Issue 2456803002: Remove OnOptInChanged callback. (Closed)
Patch Set: Address comments. Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const char kManagedAuthToken[] = "managed-auth-token"; 48 const char kManagedAuthToken[] = "managed-auth-token";
49 // Set unmanaged auth token for other Android unmanaged accounts. 49 // Set unmanaged auth token for other Android unmanaged accounts.
50 const char kUnmanagedAuthToken[] = "unmanaged-auth-token"; 50 const char kUnmanagedAuthToken[] = "unmanaged-auth-token";
51 const char kWellKnownConsumerName[] = "test@gmail.com"; 51 const char kWellKnownConsumerName[] = "test@gmail.com";
52 const char kFakeUserName[] = "test@example.com"; 52 const char kFakeUserName[] = "test@example.com";
53 53
54 } // namespace 54 } // namespace
55 55
56 namespace arc { 56 namespace arc {
57 57
58 // Base ArcAuthService observer. 58 // Observer of ARC bridge shutdown.
59 class ArcAuthServiceObserver : public ArcAuthService::Observer { 59 class ArcAuthServiceShutdownObserver : public ArcAuthService::Observer {
60 public: 60 public:
61 // ArcAuthService::Observer: 61 ArcAuthServiceShutdownObserver() { ArcAuthService::Get()->AddObserver(this); }
62 ~ArcAuthServiceObserver() override { 62
63 ~ArcAuthServiceShutdownObserver() override {
63 ArcAuthService::Get()->RemoveObserver(this); 64 ArcAuthService::Get()->RemoveObserver(this);
64 } 65 }
65 66
66 void Wait() { 67 void Wait() {
67 run_loop_.reset(new base::RunLoop); 68 run_loop_.reset(new base::RunLoop);
68 run_loop_->Run(); 69 run_loop_->Run();
69 run_loop_.reset(); 70 run_loop_.reset();
70 } 71 }
71 72
72 protected:
73 ArcAuthServiceObserver() { ArcAuthService::Get()->AddObserver(this); }
74
75 std::unique_ptr<base::RunLoop> run_loop_;
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceObserver);
79 };
80
81 // Observer of ArcAuthService state change.
82 class ArcAuthServiceStateObserver : public ArcAuthServiceObserver {
83 public:
84 ArcAuthServiceStateObserver() : ArcAuthServiceObserver() {}
85
86 // ArcAuthService::Observer:
87 void OnOptInChanged(ArcAuthService::State state) override {
88 if (!run_loop_)
89 return;
90 run_loop_->Quit();
91 }
92
93 private:
94 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceStateObserver);
95 };
96
97 // Observer of ARC bridge shutdown.
98 class ArcAuthServiceShutdownObserver : public ArcAuthServiceObserver {
99 public:
100 ArcAuthServiceShutdownObserver() : ArcAuthServiceObserver() {}
101
102 // ArcAuthService::Observer: 73 // ArcAuthService::Observer:
103 void OnShutdownBridge() override { 74 void OnShutdownBridge() override {
104 if (!run_loop_) 75 if (!run_loop_)
105 return; 76 return;
106 run_loop_->Quit(); 77 run_loop_->Quit();
107 } 78 }
108 79
109 private: 80 private:
81 std::unique_ptr<base::RunLoop> run_loop_;
82
110 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceShutdownObserver); 83 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceShutdownObserver);
111 }; 84 };
112 85
113 class ArcAuthServiceTest : public InProcessBrowserTest { 86 class ArcAuthServiceTest : public InProcessBrowserTest {
114 protected: 87 protected:
115 ArcAuthServiceTest() {} 88 ArcAuthServiceTest() {}
116 89
117 // InProcessBrowserTest: 90 // InProcessBrowserTest:
118 ~ArcAuthServiceTest() override {} 91 ~ArcAuthServiceTest() override {}
119 92
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 218
246 prefs->SetBoolean(prefs::kArcEnabled, true); 219 prefs->SetBoolean(prefs::kArcEnabled, true);
247 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, 220 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken,
248 base::Time::Max()); 221 base::Time::Max());
249 ArcAuthServiceShutdownObserver observer; 222 ArcAuthServiceShutdownObserver observer;
250 observer.Wait(); 223 observer.Wait();
251 ASSERT_EQ(ArcAuthService::State::STOPPED, ArcAuthService::Get()->state()); 224 ASSERT_EQ(ArcAuthService::State::STOPPED, ArcAuthService::Get()->state());
252 } 225 }
253 226
254 } // namespace arc 227 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.cc ('k') | chrome/browser/chromeos/extensions/gfx_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698