| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return; | 88 return; |
| 88 run_loop_->Quit(); | 89 run_loop_->Quit(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 std::unique_ptr<base::RunLoop> run_loop_; | 93 std::unique_ptr<base::RunLoop> run_loop_; |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); | 95 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 // Observer of ARC data has been removed. | |
| 98 class ArcSessionManagerDataRemovedObserver | |
| 99 : public ArcSessionManager::Observer { | |
| 100 public: | |
| 101 ArcSessionManagerDataRemovedObserver() { | |
| 102 ArcSessionManager::Get()->AddObserver(this); | |
| 103 } | |
| 104 | |
| 105 ~ArcSessionManagerDataRemovedObserver() override { | |
| 106 ArcSessionManager::Get()->RemoveObserver(this); | |
| 107 } | |
| 108 | |
| 109 void Wait() { | |
| 110 run_loop_.reset(new base::RunLoop); | |
| 111 run_loop_->Run(); | |
| 112 run_loop_.reset(); | |
| 113 } | |
| 114 | |
| 115 // ArcSessionManager::Observer: | |
| 116 void OnArcDataRemoved() override { | |
| 117 if (!run_loop_) | |
| 118 return; | |
| 119 run_loop_->Quit(); | |
| 120 } | |
| 121 | |
| 122 private: | |
| 123 std::unique_ptr<base::RunLoop> run_loop_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerDataRemovedObserver); | |
| 126 }; | |
| 127 | |
| 128 class ArcSessionManagerTest : public InProcessBrowserTest { | 98 class ArcSessionManagerTest : public InProcessBrowserTest { |
| 129 protected: | 99 protected: |
| 130 ArcSessionManagerTest() {} | 100 ArcSessionManagerTest() {} |
| 131 | 101 |
| 132 // InProcessBrowserTest: | 102 // InProcessBrowserTest: |
| 133 ~ArcSessionManagerTest() override {} | 103 ~ArcSessionManagerTest() override {} |
| 134 | 104 |
| 135 void SetUpCommandLine(base::CommandLine* command_line) override { | 105 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 136 InProcessBrowserTest::SetUpCommandLine(command_line); | 106 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 137 arc::SetArcAvailableCommandLineForTesting(command_line); | 107 arc::SetArcAvailableCommandLineForTesting(command_line); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 #else | 230 #else |
| 261 #define MAYBE_ManagedAndroidAccount ManagedAndroidAccount | 231 #define MAYBE_ManagedAndroidAccount ManagedAndroidAccount |
| 262 #endif | 232 #endif |
| 263 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, MAYBE_ManagedAndroidAccount) { | 233 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, MAYBE_ManagedAndroidAccount) { |
| 264 EnableArc(); | 234 EnableArc(); |
| 265 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 235 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 266 base::Time::Max()); | 236 base::Time::Max()); |
| 267 ArcSessionManagerShutdownObserver().Wait(); | 237 ArcSessionManagerShutdownObserver().Wait(); |
| 268 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 238 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 269 ArcSessionManager::Get()->state()); | 239 ArcSessionManager::Get()->state()); |
| 270 ArcSessionManagerDataRemovedObserver().Wait(); | 240 ArcDataRemovedWaiter().Wait(); |
| 271 ASSERT_EQ(ArcSessionManager::State::STOPPED, | 241 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
| 272 ArcSessionManager::Get()->state()); | 242 ArcSessionManager::Get()->state()); |
| 273 } | 243 } |
| 274 | 244 |
| 275 } // namespace arc | 245 } // namespace arc |
| OLD | NEW |