| OLD | NEW |
| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" | 16 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 17 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 18 #include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h" |
| 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 21 #include "chrome/browser/policy/cloud/test_request_interceptor.h" | 22 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector.h" | 23 #include "chrome/browser/policy/profile_policy_connector.h" |
| 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 24 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 24 #include "chrome/browser/policy/test/local_policy_test_server.h" | 25 #include "chrome/browser/policy/test/local_policy_test_server.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 27 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return; | 87 return; |
| 87 run_loop_->Quit(); | 88 run_loop_->Quit(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 std::unique_ptr<base::RunLoop> run_loop_; | 92 std::unique_ptr<base::RunLoop> run_loop_; |
| 92 | 93 |
| 93 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); | 94 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 // Observer of ARC data has been removed. | |
| 97 class ArcSessionManagerDataRemovedObserver | |
| 98 : public ArcSessionManager::Observer { | |
| 99 public: | |
| 100 ArcSessionManagerDataRemovedObserver() { | |
| 101 ArcSessionManager::Get()->AddObserver(this); | |
| 102 } | |
| 103 | |
| 104 ~ArcSessionManagerDataRemovedObserver() override { | |
| 105 ArcSessionManager::Get()->RemoveObserver(this); | |
| 106 } | |
| 107 | |
| 108 void Wait() { | |
| 109 run_loop_.reset(new base::RunLoop); | |
| 110 run_loop_->Run(); | |
| 111 run_loop_.reset(); | |
| 112 } | |
| 113 | |
| 114 // ArcSessionManager::Observer: | |
| 115 void OnArcDataRemoved() override { | |
| 116 if (!run_loop_) | |
| 117 return; | |
| 118 run_loop_->Quit(); | |
| 119 } | |
| 120 | |
| 121 private: | |
| 122 std::unique_ptr<base::RunLoop> run_loop_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerDataRemovedObserver); | |
| 125 }; | |
| 126 | |
| 127 class ArcSessionManagerTest : public InProcessBrowserTest { | 97 class ArcSessionManagerTest : public InProcessBrowserTest { |
| 128 protected: | 98 protected: |
| 129 ArcSessionManagerTest() {} | 99 ArcSessionManagerTest() {} |
| 130 | 100 |
| 131 // InProcessBrowserTest: | 101 // InProcessBrowserTest: |
| 132 ~ArcSessionManagerTest() override {} | 102 ~ArcSessionManagerTest() override {} |
| 133 | 103 |
| 134 void SetUpCommandLine(base::CommandLine* command_line) override { | 104 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 135 InProcessBrowserTest::SetUpCommandLine(command_line); | 105 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 136 arc::SetArcAvailableCommandLineForTesting(command_line); | 106 arc::SetArcAvailableCommandLineForTesting(command_line); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 #else | 229 #else |
| 260 #define MAYBE_ManagedAndroidAccount ManagedAndroidAccount | 230 #define MAYBE_ManagedAndroidAccount ManagedAndroidAccount |
| 261 #endif | 231 #endif |
| 262 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, MAYBE_ManagedAndroidAccount) { | 232 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, MAYBE_ManagedAndroidAccount) { |
| 263 EnableArc(); | 233 EnableArc(); |
| 264 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 234 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 265 base::Time::Max()); | 235 base::Time::Max()); |
| 266 ArcSessionManagerShutdownObserver().Wait(); | 236 ArcSessionManagerShutdownObserver().Wait(); |
| 267 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 237 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 268 ArcSessionManager::Get()->state()); | 238 ArcSessionManager::Get()->state()); |
| 269 ArcSessionManagerDataRemovedObserver().Wait(); | 239 ArcDataRemovedWaiter().Wait(); |
| 270 ASSERT_EQ(ArcSessionManager::State::STOPPED, | 240 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
| 271 ArcSessionManager::Get()->state()); | 241 ArcSessionManager::Get()->state()); |
| 272 } | 242 } |
| 273 | 243 |
| 274 } // namespace arc | 244 } // namespace arc |
| OLD | NEW |