| OLD | NEW |
| 1 /// Copyright 2014 The Chromium Authors. All rights reserved. | 1 /// Copyright 2014 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 "athena/activity/public/activity_factory.h" | 5 #include "athena/activity/public/activity_factory.h" |
| 6 #include "athena/activity/public/activity_manager.h" | 6 #include "athena/activity/public/activity_manager.h" |
| 7 #include "athena/content/app_activity.h" | 7 #include "athena/content/app_activity.h" |
| 8 #include "athena/content/app_activity_registry.h" | 8 #include "athena/content/app_activity_registry.h" |
| 9 #include "athena/content/public/app_registry.h" | 9 #include "athena/content/public/app_registry.h" |
| 10 #include "athena/extensions/public/extensions_delegate.h" | 10 #include "athena/extensions/public/extensions_delegate.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 class TestAppActivity : public AppActivity { | 33 class TestAppActivity : public AppActivity { |
| 34 public: | 34 public: |
| 35 explicit TestAppActivity(const std::string& app_id) | 35 explicit TestAppActivity(const std::string& app_id) |
| 36 : AppActivity(app_id), | 36 : AppActivity(app_id), |
| 37 view_(new views::View()), | 37 view_(new views::View()), |
| 38 current_state_(ACTIVITY_VISIBLE) { | 38 current_state_(ACTIVITY_VISIBLE) { |
| 39 app_activity_registry_ = | 39 app_activity_registry_ = |
| 40 AppRegistry::Get()->GetAppActivityRegistry(app_id, nullptr); | 40 AppRegistry::Get()->GetAppActivityRegistry(app_id, nullptr); |
| 41 app_activity_registry_->RegisterAppActivity(this); | 41 app_activity_registry_->RegisterAppActivity(this); |
| 42 } | 42 } |
| 43 virtual ~TestAppActivity() { | 43 ~TestAppActivity() override { |
| 44 app_activity_registry_->UnregisterAppActivity(this); | 44 app_activity_registry_->UnregisterAppActivity(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 AppActivityRegistry* app_activity_registry() { | 47 AppActivityRegistry* app_activity_registry() { |
| 48 return app_activity_registry_; | 48 return app_activity_registry_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Activity: | 51 // Activity: |
| 52 virtual ActivityViewModel* GetActivityViewModel() override { | 52 ActivityViewModel* GetActivityViewModel() override { return this; } |
| 53 return this; | 53 void SetCurrentState(Activity::ActivityState state) override { |
| 54 } | |
| 55 virtual void SetCurrentState(Activity::ActivityState state) override { | |
| 56 current_state_ = state; | 54 current_state_ = state; |
| 57 if (state == ACTIVITY_UNLOADED) | 55 if (state == ACTIVITY_UNLOADED) |
| 58 app_activity_registry_->Unload(); | 56 app_activity_registry_->Unload(); |
| 59 } | 57 } |
| 60 virtual ActivityState GetCurrentState() override { | 58 ActivityState GetCurrentState() override { return current_state_; } |
| 61 return current_state_; | 59 bool IsVisible() override { return true; } |
| 62 } | 60 ActivityMediaState GetMediaState() override { |
| 63 virtual bool IsVisible() override { | |
| 64 return true; | |
| 65 } | |
| 66 virtual ActivityMediaState GetMediaState() override { | |
| 67 return Activity::ACTIVITY_MEDIA_STATE_NONE; | 61 return Activity::ACTIVITY_MEDIA_STATE_NONE; |
| 68 } | 62 } |
| 69 virtual aura::Window* GetWindow() override { | 63 aura::Window* GetWindow() override { |
| 70 return view_->GetWidget()->GetNativeWindow(); | 64 return view_->GetWidget()->GetNativeWindow(); |
| 71 } | 65 } |
| 72 | 66 |
| 73 // ActivityViewModel: | 67 // ActivityViewModel: |
| 74 virtual void Init() override {} | 68 void Init() override {} |
| 75 virtual SkColor GetRepresentativeColor() const override { return 0; } | 69 SkColor GetRepresentativeColor() const override { return 0; } |
| 76 virtual base::string16 GetTitle() const override { return title_; } | 70 base::string16 GetTitle() const override { return title_; } |
| 77 virtual bool UsesFrame() const override { return true; } | 71 bool UsesFrame() const override { return true; } |
| 78 virtual views::View* GetContentsView() override { return view_; } | 72 views::View* GetContentsView() override { return view_; } |
| 79 virtual views::Widget* CreateWidget() override { return nullptr; } | 73 views::Widget* CreateWidget() override { return nullptr; } |
| 80 virtual gfx::ImageSkia GetOverviewModeImage() override { | 74 gfx::ImageSkia GetOverviewModeImage() override { return gfx::ImageSkia(); } |
| 81 return gfx::ImageSkia(); | |
| 82 } | |
| 83 | 75 |
| 84 private: | 76 private: |
| 85 // If known the registry which holds all activities for the associated app. | 77 // If known the registry which holds all activities for the associated app. |
| 86 AppActivityRegistry* app_activity_registry_; | 78 AppActivityRegistry* app_activity_registry_; |
| 87 | 79 |
| 88 // The title of the activity. | 80 // The title of the activity. |
| 89 base::string16 title_; | 81 base::string16 title_; |
| 90 | 82 |
| 91 // Our view. | 83 // Our view. |
| 92 views::View* view_; | 84 views::View* view_; |
| 93 | 85 |
| 94 // The current state for this activity. | 86 // The current state for this activity. |
| 95 ActivityState current_state_; | 87 ActivityState current_state_; |
| 96 | 88 |
| 97 DISALLOW_COPY_AND_ASSIGN(TestAppActivity); | 89 DISALLOW_COPY_AND_ASSIGN(TestAppActivity); |
| 98 }; | 90 }; |
| 99 | 91 |
| 100 // An AppContentDelegateClass which we can query for call stats. | 92 // An AppContentDelegateClass which we can query for call stats. |
| 101 class TestExtensionsDelegate : public ExtensionsDelegate { | 93 class TestExtensionsDelegate : public ExtensionsDelegate { |
| 102 public: | 94 public: |
| 103 TestExtensionsDelegate() : unload_called_(0), restart_called_(0) {} | 95 TestExtensionsDelegate() : unload_called_(0), restart_called_(0) {} |
| 104 virtual ~TestExtensionsDelegate() {} | 96 ~TestExtensionsDelegate() override {} |
| 105 | 97 |
| 106 int unload_called() const { return unload_called_; } | 98 int unload_called() const { return unload_called_; } |
| 107 int restart_called() const { return restart_called_; } | 99 int restart_called() const { return restart_called_; } |
| 108 | 100 |
| 109 // ExtensionsDelegate: | 101 // ExtensionsDelegate: |
| 110 virtual content::BrowserContext* GetBrowserContext() const override { | 102 content::BrowserContext* GetBrowserContext() const override { |
| 111 return nullptr; | 103 return nullptr; |
| 112 } | 104 } |
| 113 virtual const extensions::ExtensionSet& GetInstalledExtensions() override { | 105 const extensions::ExtensionSet& GetInstalledExtensions() override { |
| 114 return extension_set_; | 106 return extension_set_; |
| 115 } | 107 } |
| 116 // Unload an application. Returns true when unloaded. | 108 // Unload an application. Returns true when unloaded. |
| 117 virtual bool UnloadApp(const std::string& app_id) override { | 109 bool UnloadApp(const std::string& app_id) override { |
| 118 unload_called_++; | 110 unload_called_++; |
| 119 // Since we did not close anything we let the framework clean up. | 111 // Since we did not close anything we let the framework clean up. |
| 120 return false; | 112 return false; |
| 121 } | 113 } |
| 122 // Restarts an application. Returns true when the restart was initiated. | 114 // Restarts an application. Returns true when the restart was initiated. |
| 123 virtual bool LaunchApp(const std::string& app_id) override { | 115 bool LaunchApp(const std::string& app_id) override { |
| 124 restart_called_++; | 116 restart_called_++; |
| 125 return true; | 117 return true; |
| 126 } | 118 } |
| 127 virtual scoped_ptr<extensions::ExtensionInstallUI> CreateExtensionInstallUI() | 119 scoped_ptr<extensions::ExtensionInstallUI> CreateExtensionInstallUI() |
| 128 override { | 120 override { |
| 129 return scoped_ptr<extensions::ExtensionInstallUI>(); | 121 return scoped_ptr<extensions::ExtensionInstallUI>(); |
| 130 } | 122 } |
| 131 | 123 |
| 132 private: | 124 private: |
| 133 int unload_called_; | 125 int unload_called_; |
| 134 int restart_called_; | 126 int restart_called_; |
| 135 | 127 |
| 136 extensions::ExtensionSet extension_set_; | 128 extensions::ExtensionSet extension_set_; |
| 137 | 129 |
| 138 DISALLOW_COPY_AND_ASSIGN(TestExtensionsDelegate); | 130 DISALLOW_COPY_AND_ASSIGN(TestExtensionsDelegate); |
| 139 }; | 131 }; |
| 140 | 132 |
| 141 } // namespace | 133 } // namespace |
| 142 | 134 |
| 143 // Our testing base. | 135 // Our testing base. |
| 144 class AppActivityTest : public AthenaTestBase { | 136 class AppActivityTest : public AthenaTestBase { |
| 145 public: | 137 public: |
| 146 AppActivityTest() : test_extensions_delegate_(nullptr) {} | 138 AppActivityTest() : test_extensions_delegate_(nullptr) {} |
| 147 virtual ~AppActivityTest() {} | 139 ~AppActivityTest() override {} |
| 148 | 140 |
| 149 // AthenaTestBase: | 141 // AthenaTestBase: |
| 150 virtual void SetUp() override { | 142 void SetUp() override { |
| 151 AthenaTestBase::SetUp(); | 143 AthenaTestBase::SetUp(); |
| 152 // Create and install our TestAppContentDelegate with instrumentation. | 144 // Create and install our TestAppContentDelegate with instrumentation. |
| 153 ExtensionsDelegate::Shutdown(); | 145 ExtensionsDelegate::Shutdown(); |
| 154 // The instance will be deleted by ExtensionsDelegate::Shutdown(). | 146 // The instance will be deleted by ExtensionsDelegate::Shutdown(). |
| 155 test_extensions_delegate_ = new TestExtensionsDelegate(); | 147 test_extensions_delegate_ = new TestExtensionsDelegate(); |
| 156 } | 148 } |
| 157 | 149 |
| 158 // A function to create an Activity. | 150 // A function to create an Activity. |
| 159 TestAppActivity* CreateAppActivity(const std::string& app_id) { | 151 TestAppActivity* CreateAppActivity(const std::string& app_id) { |
| 160 TestAppActivity* activity = new TestAppActivity(app_id); | 152 TestAppActivity* activity = new TestAppActivity(app_id); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // However - the restart in this test framework does not really restart and | 423 // However - the restart in this test framework does not really restart and |
| 432 // all objects should be still there.. | 424 // all objects should be still there.. |
| 433 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); | 425 EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications()); |
| 434 EXPECT_TRUE(app_activity_registry->unloaded_activity_proxy()); | 426 EXPECT_TRUE(app_activity_registry->unloaded_activity_proxy()); |
| 435 Activity::Delete(app_activity_registry->unloaded_activity_proxy()); | 427 Activity::Delete(app_activity_registry->unloaded_activity_proxy()); |
| 436 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); | 428 EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications()); |
| 437 } | 429 } |
| 438 | 430 |
| 439 } // namespace test | 431 } // namespace test |
| 440 } // namespace athena | 432 } // namespace athena |
| OLD | NEW |