| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual 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 virtual 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 virtual void OnKioskExtensionLoadedInCache( |
| 147 const std::string& app_id) OVERRIDE { | 147 const std::string& app_id) override { |
| 148 OnKioskAppDataChanged(app_id); | 148 OnKioskAppDataChanged(app_id); |
| 149 } | 149 } |
| 150 | 150 |
| 151 virtual void OnKioskExtensionDownloadFailed( | 151 virtual void OnKioskExtensionDownloadFailed( |
| 152 const std::string& app_id) OVERRIDE { | 152 const std::string& app_id) override { |
| 153 OnKioskAppDataLoadFailure(app_id); | 153 OnKioskAppDataLoadFailure(app_id); |
| 154 } | 154 } |
| 155 | 155 |
| 156 scoped_refptr<content::MessageLoopRunner> runner_; | 156 scoped_refptr<content::MessageLoopRunner> runner_; |
| 157 KioskAppManager* manager_; | 157 KioskAppManager* manager_; |
| 158 bool loaded_; | 158 bool loaded_; |
| 159 bool quit_; | 159 bool quit_; |
| 160 int data_change_count_; | 160 int data_change_count_; |
| 161 int data_loaded_threshold_; | 161 int data_loaded_threshold_; |
| 162 | 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); | 163 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 } // namespace | 166 } // namespace |
| 167 | 167 |
| 168 class KioskAppManagerTest : public InProcessBrowserTest { | 168 class KioskAppManagerTest : public InProcessBrowserTest { |
| 169 public: | 169 public: |
| 170 KioskAppManagerTest() : fake_cws_(new FakeCWS()) {} | 170 KioskAppManagerTest() : fake_cws_(new FakeCWS()) {} |
| 171 virtual ~KioskAppManagerTest() {} | 171 virtual ~KioskAppManagerTest() {} |
| 172 | 172 |
| 173 // InProcessBrowserTest overrides: | 173 // InProcessBrowserTest overrides: |
| 174 virtual void SetUp() OVERRIDE { | 174 virtual void SetUp() override { |
| 175 base::FilePath test_data_dir; | 175 base::FilePath test_data_dir; |
| 176 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 176 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 177 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 177 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 178 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 178 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 179 // Stop IO thread here because no threads are allowed while | 179 // Stop IO thread here because no threads are allowed while |
| 180 // spawning sandbox host process. See crbug.com/322732. | 180 // spawning sandbox host process. See crbug.com/322732. |
| 181 embedded_test_server()->StopThread(); | 181 embedded_test_server()->StopThread(); |
| 182 | 182 |
| 183 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 183 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 184 | 184 |
| 185 InProcessBrowserTest::SetUp(); | 185 InProcessBrowserTest::SetUp(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 188 virtual void SetUpCommandLine(CommandLine* command_line) override { |
| 189 InProcessBrowserTest::SetUpCommandLine(command_line); | 189 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 190 | 190 |
| 191 // Initialize fake_cws_ to setup web store gallery. | 191 // Initialize fake_cws_ to setup web store gallery. |
| 192 fake_cws_->Init(embedded_test_server()); | 192 fake_cws_->Init(embedded_test_server()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 virtual void SetUpOnMainThread() OVERRIDE { | 195 virtual void SetUpOnMainThread() override { |
| 196 InProcessBrowserTest::SetUpOnMainThread(); | 196 InProcessBrowserTest::SetUpOnMainThread(); |
| 197 | 197 |
| 198 // Restart the thread as the sandbox host process has already been spawned. | 198 // Restart the thread as the sandbox host process has already been spawned. |
| 199 embedded_test_server()->RestartThreadAndListen(); | 199 embedded_test_server()->RestartThreadAndListen(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 202 virtual void SetUpInProcessBrowserTestFixture() override { |
| 203 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 203 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 204 | 204 |
| 205 host_resolver()->AddRule("*", "127.0.0.1"); | 205 host_resolver()->AddRule("*", "127.0.0.1"); |
| 206 } | 206 } |
| 207 | 207 |
| 208 std::string GetAppIds() const { | 208 std::string GetAppIds() const { |
| 209 KioskAppManager::Apps apps; | 209 KioskAppManager::Apps apps; |
| 210 manager()->GetApps(&apps); | 210 manager()->GetApps(&apps); |
| 211 | 211 |
| 212 std::string str; | 212 std::string str; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 manager()->GetConsumerKioskAutoLaunchStatus( | 683 manager()->GetConsumerKioskAutoLaunchStatus( |
| 684 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 684 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 685 status.get(), | 685 status.get(), |
| 686 runner3->QuitClosure())); | 686 runner3->QuitClosure())); |
| 687 runner3->Run(); | 687 runner3->Run(); |
| 688 EXPECT_EQ(*status.get(), | 688 EXPECT_EQ(*status.get(), |
| 689 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); | 689 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| 690 } | 690 } |
| 691 | 691 |
| 692 } // namespace chromeos | 692 } // namespace chromeos |
| OLD | NEW |