1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/prefs/pref_service.h" 6 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/common/pref_names.h" 10 11 #if defined(OS_CHROMEOS) 12 #include "chromeos/dbus/fake_dbus_thread_manager.h" 13 #include "chromeos/dbus/fake_update_engine_client.h" 14 15 using chromeos::UpdateEngineClient; 16 #endif 17 18 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetIncognitoModeAvailability) { 19 PrefService* pref_service = browser()->profile()->GetPrefs(); 20 pref_service->SetInteger(prefs::kIncognitoModeAvailability, 1); 21 22 EXPECT_TRUE(RunComponentExtensionTest( 23 "system/get_incognito_mode_availability")) << message_; 24 } 25 26 #if defined(OS_CHROMEOS) 27 28 class GetUpdateStatusApiTest : public ExtensionApiTest { 29 public: 30 GetUpdateStatusApiTest() : fake_update_engine_client_(NULL) {} 31 32 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 33 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 34 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager = 35 new chromeos::FakeDBusThreadManager; 36 fake_dbus_thread_manager->SetFakeClients(); 37 fake_update_engine_client_ = new chromeos::FakeUpdateEngineClient; 38 fake_dbus_thread_manager->SetUpdateEngineClient( 39 scoped_ptr<UpdateEngineClient>(fake_update_engine_client_)); 40 chromeos::DBusThreadManager::SetInstanceForTesting( 41 fake_dbus_thread_manager); 42 } 43 44 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 45 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); 46 } 47 48 protected: 49 chromeos::FakeUpdateEngineClient* fake_update_engine_client_; 50 51 private: 52 DISALLOW_COPY_AND_ASSIGN(GetUpdateStatusApiTest); 53 }; 54 55 IN_PROC_BROWSER_TEST_F(GetUpdateStatusApiTest, Progress) { 56 UpdateEngineClient::Status status_not_available; 57 status_not_available.status = UpdateEngineClient::UPDATE_STATUS_IDLE; 58 UpdateEngineClient::Status status_updating; 59 status_updating.status = UpdateEngineClient::UPDATE_STATUS_DOWNLOADING; 60 status_updating.download_progress = 0.5; 61 UpdateEngineClient::Status status_boot_needed; 62 status_boot_needed.status = 63 UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; 64 65 // The fake client returns the last status in this order. 66 fake_update_engine_client_->PushLastStatus(status_not_available); 67 fake_update_engine_client_->PushLastStatus(status_updating); 68 fake_update_engine_client_->PushLastStatus(status_boot_needed); 69 70 ASSERT_TRUE(RunComponentExtensionTest( 71 "system/get_update_status")) << message_; 72 } 73 74 #endif 75