| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.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 Loading... |
| 106 AppDataLoadWaiter(KioskAppManager* manager, int data_loaded_threshold) | 106 AppDataLoadWaiter(KioskAppManager* manager, int data_loaded_threshold) |
| 107 : runner_(NULL), | 107 : runner_(NULL), |
| 108 manager_(manager), | 108 manager_(manager), |
| 109 loaded_(false), | 109 loaded_(false), |
| 110 quit_(false), | 110 quit_(false), |
| 111 data_change_count_(0), | 111 data_change_count_(0), |
| 112 data_loaded_threshold_(data_loaded_threshold) { | 112 data_loaded_threshold_(data_loaded_threshold) { |
| 113 manager_->AddObserver(this); | 113 manager_->AddObserver(this); |
| 114 } | 114 } |
| 115 | 115 |
| 116 virtual ~AppDataLoadWaiter() { manager_->RemoveObserver(this); } | 116 ~AppDataLoadWaiter() override { manager_->RemoveObserver(this); } |
| 117 | 117 |
| 118 void Wait() { | 118 void Wait() { |
| 119 if (quit_) | 119 if (quit_) |
| 120 return; | 120 return; |
| 121 runner_ = new content::MessageLoopRunner; | 121 runner_ = new content::MessageLoopRunner; |
| 122 runner_->Run(); | 122 runner_->Run(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool loaded() const { return loaded_; } | 125 bool loaded() const { return loaded_; } |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 // KioskAppManagerObserver overrides: | 128 // KioskAppManagerObserver overrides: |
| 129 virtual void OnKioskAppDataChanged(const std::string& app_id) override { | 129 void OnKioskAppDataChanged(const std::string& app_id) override { |
| 130 ++data_change_count_; | 130 ++data_change_count_; |
| 131 if (data_change_count_ < data_loaded_threshold_) | 131 if (data_change_count_ < data_loaded_threshold_) |
| 132 return; | 132 return; |
| 133 loaded_ = true; | 133 loaded_ = true; |
| 134 quit_ = true; | 134 quit_ = true; |
| 135 if (runner_.get()) | 135 if (runner_.get()) |
| 136 runner_->Quit(); | 136 runner_->Quit(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 virtual void OnKioskAppDataLoadFailure(const std::string& app_id) override { | 139 void OnKioskAppDataLoadFailure(const std::string& app_id) override { |
| 140 loaded_ = false; | 140 loaded_ = false; |
| 141 quit_ = true; | 141 quit_ = true; |
| 142 if (runner_.get()) | 142 if (runner_.get()) |
| 143 runner_->Quit(); | 143 runner_->Quit(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 virtual void OnKioskExtensionLoadedInCache( | 146 void OnKioskExtensionLoadedInCache(const std::string& app_id) override { |
| 147 const std::string& app_id) override { | |
| 148 OnKioskAppDataChanged(app_id); | 147 OnKioskAppDataChanged(app_id); |
| 149 } | 148 } |
| 150 | 149 |
| 151 virtual void OnKioskExtensionDownloadFailed( | 150 void OnKioskExtensionDownloadFailed(const std::string& app_id) override { |
| 152 const std::string& app_id) override { | |
| 153 OnKioskAppDataLoadFailure(app_id); | 151 OnKioskAppDataLoadFailure(app_id); |
| 154 } | 152 } |
| 155 | 153 |
| 156 scoped_refptr<content::MessageLoopRunner> runner_; | 154 scoped_refptr<content::MessageLoopRunner> runner_; |
| 157 KioskAppManager* manager_; | 155 KioskAppManager* manager_; |
| 158 bool loaded_; | 156 bool loaded_; |
| 159 bool quit_; | 157 bool quit_; |
| 160 int data_change_count_; | 158 int data_change_count_; |
| 161 int data_loaded_threshold_; | 159 int data_loaded_threshold_; |
| 162 | 160 |
| 163 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); | 161 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); |
| 164 }; | 162 }; |
| 165 | 163 |
| 166 } // namespace | 164 } // namespace |
| 167 | 165 |
| 168 class KioskAppManagerTest : public InProcessBrowserTest { | 166 class KioskAppManagerTest : public InProcessBrowserTest { |
| 169 public: | 167 public: |
| 170 KioskAppManagerTest() : fake_cws_(new FakeCWS()) {} | 168 KioskAppManagerTest() : fake_cws_(new FakeCWS()) {} |
| 171 virtual ~KioskAppManagerTest() {} | 169 ~KioskAppManagerTest() override {} |
| 172 | 170 |
| 173 // InProcessBrowserTest overrides: | 171 // InProcessBrowserTest overrides: |
| 174 virtual void SetUp() override { | 172 void SetUp() override { |
| 175 base::FilePath test_data_dir; | 173 base::FilePath test_data_dir; |
| 176 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 174 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 177 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 175 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 178 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 176 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 179 // Stop IO thread here because no threads are allowed while | 177 // Stop IO thread here because no threads are allowed while |
| 180 // spawning sandbox host process. See crbug.com/322732. | 178 // spawning sandbox host process. See crbug.com/322732. |
| 181 embedded_test_server()->StopThread(); | 179 embedded_test_server()->StopThread(); |
| 182 | 180 |
| 183 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 181 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 184 | 182 |
| 185 InProcessBrowserTest::SetUp(); | 183 InProcessBrowserTest::SetUp(); |
| 186 } | 184 } |
| 187 | 185 |
| 188 virtual void SetUpCommandLine(base::CommandLine* command_line) override { | 186 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 189 InProcessBrowserTest::SetUpCommandLine(command_line); | 187 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 190 | 188 |
| 191 // Initialize fake_cws_ to setup web store gallery. | 189 // Initialize fake_cws_ to setup web store gallery. |
| 192 fake_cws_->Init(embedded_test_server()); | 190 fake_cws_->Init(embedded_test_server()); |
| 193 } | 191 } |
| 194 | 192 |
| 195 virtual void SetUpOnMainThread() override { | 193 void SetUpOnMainThread() override { |
| 196 InProcessBrowserTest::SetUpOnMainThread(); | 194 InProcessBrowserTest::SetUpOnMainThread(); |
| 197 | 195 |
| 198 // Restart the thread as the sandbox host process has already been spawned. | 196 // Restart the thread as the sandbox host process has already been spawned. |
| 199 embedded_test_server()->RestartThreadAndListen(); | 197 embedded_test_server()->RestartThreadAndListen(); |
| 200 } | 198 } |
| 201 | 199 |
| 202 virtual void SetUpInProcessBrowserTestFixture() override { | 200 void SetUpInProcessBrowserTestFixture() override { |
| 203 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 201 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 204 | 202 |
| 205 host_resolver()->AddRule("*", "127.0.0.1"); | 203 host_resolver()->AddRule("*", "127.0.0.1"); |
| 206 } | 204 } |
| 207 | 205 |
| 208 std::string GetAppIds() const { | 206 std::string GetAppIds() const { |
| 209 KioskAppManager::Apps apps; | 207 KioskAppManager::Apps apps; |
| 210 manager()->GetApps(&apps); | 208 manager()->GetApps(&apps); |
| 211 | 209 |
| 212 std::string str; | 210 std::string str; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 manager()->GetConsumerKioskAutoLaunchStatus( | 681 manager()->GetConsumerKioskAutoLaunchStatus( |
| 684 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 682 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 685 status.get(), | 683 status.get(), |
| 686 runner3->QuitClosure())); | 684 runner3->QuitClosure())); |
| 687 runner3->Run(); | 685 runner3->Run(); |
| 688 EXPECT_EQ(*status.get(), | 686 EXPECT_EQ(*status.get(), |
| 689 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); | 687 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| 690 } | 688 } |
| 691 | 689 |
| 692 } // namespace chromeos | 690 } // namespace chromeos |
| OLD | NEW |