Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2751)

Unified Diff: athena/content/app_activity_unittest.cc

Issue 477523002: Athena: Adding basic resource management framework (un-/re-loading) of V2 applications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: athena/content/app_activity_unittest.cc
diff --git a/athena/content/app_activity_unittest.cc b/athena/content/app_activity_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d433e8782ebf2582251a8f24e09c7dbd3c9fa5f
--- /dev/null
+++ b/athena/content/app_activity_unittest.cc
@@ -0,0 +1,249 @@
+/// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "athena/activity/public/activity_manager.h"
+
+#include "athena/activity/public/activity_factory.h"
+#include "athena/content/app_activity.h"
+#include "athena/content/app_activity_registry.h"
+#include "athena/content/public/app_content_delegate.h"
+#include "athena/content/public/app_registry.h"
+#include "athena/test/athena_test_base.h"
+#include "extensions/shell/browser/shell_app_window.h"
+#include "ui/views/view.h"
+
+
+namespace content {
+class BrowserContext;
+}
+
+namespace athena {
+namespace test {
+
+namespace {
+
+// An identifier for the running apps.
+const char kDummyApp1[] = "aaaaaaa";
+const char kDummyApp2[] = "bbbbbbb";
+
+// A dummy test app activity which works without content / ShellAppWindow.
+class TestAppActivity : public AppActivity {
+ public:
+ explicit TestAppActivity(const std::string& app_id) :
+ AppActivity(NULL),
+ app_id_(app_id),
+ view_(new views::View()) {
+ app_activity_registry_ =
+ AppRegistry::Get()->GetAppActivityRegistry(app_id, NULL);
+ app_activity_registry_->RegisterAppActivity(this);
+ }
+ virtual ~TestAppActivity() {
+ app_activity_registry_->UnregisterAppActivity(this);
+ // We need to remove ourselves here since the activity will not be destroyed
+ // with the window closure.
+ ActivityManager::Get()->RemoveActivity(this);
+ }
+
+ AppActivityRegistry* app_activity_registry() {
+ return app_activity_registry_;
+ }
+
+ // Activity:
+ virtual ActivityViewModel* GetActivityViewModel() OVERRIDE {
+ return this;
+ }
+ virtual bool IsVisible() OVERRIDE {
+ return true;
+ }
+ virtual ActivityMediaState GetMediaState() OVERRIDE {
+ return Activity::ACTIVITY_MEDIA_STATE_NONE;
+ }
+ virtual aura::Window* GetWindow() OVERRIDE { return NULL; }
+
+ // ActivityViewModel:
+ virtual void Init() OVERRIDE {}
+ virtual SkColor GetRepresentativeColor() const OVERRIDE { return 0; }
+ virtual base::string16 GetTitle() const OVERRIDE { return title_; }
+ virtual bool UsesFrame() const OVERRIDE { return true; }
+ virtual views::View* GetContentsView() OVERRIDE { return view_; }
+ virtual void CreateOverviewModeImage() OVERRIDE {}
+
+ private:
+ // If known the registry which holds all activities for the associated app.
+ AppActivityRegistry* app_activity_registry_;
+
+ // The application ID.
+ const std::string& app_id_;
+
+ // The title of the activity.
+ base::string16 title_;
+
+ // Our view.
+ views::View* view_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestAppActivity);
+};
+
+// An AppContentDelegateClass which we can query for call stats.
+class TestAppContentDelegate : public AppContentDelegate {
+ public:
+ TestAppContentDelegate() : unload_called_(0),
+ restart_called_(0) {}
+ virtual ~TestAppContentDelegate() {}
+
+ int unload_called() { return unload_called_; }
+ int restart_called() { return restart_called_; }
+ void SetExtensionID(const std::string& extension_id) {
+ extension_id_to_return_ = extension_id;
+ }
+
+ // Unload an application. Returns true when unloaded.
+ virtual bool UnloadApplication(
+ const std::string& app_id,
+ content::BrowserContext* browser_context) OVERRIDE {
+ unload_called_++;
+ return true;
+ }
+ // Restarts an application. Returns true when the restart was initiated.
+ virtual bool RestartApplication(
+ const std::string& app_id,
+ content::BrowserContext* browser_context) OVERRIDE {
+ restart_called_++;
+ return true;
+ }
+ // Returns the application ID (or an empty string) for a given web content.
+ virtual std::string GetExtensionID(
+ content::WebContents* web_contents) OVERRIDE {
+ return extension_id_to_return_;
+ }
+
+ private:
+ int unload_called_;
+ int restart_called_;
+ std::string extension_id_to_return_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestAppContentDelegate);
+};
+
+} // namespace
+
+// Our testing base.
+class AppActivityTest : public AthenaTestBase {
+ public:
+ AppActivityTest() : test_app_content_delegate_(NULL) {}
+ virtual ~AppActivityTest() {}
+
+ // AthenaTestBase:
+ virtual void SetUp() OVERRIDE {
+ AthenaTestBase::SetUp();
+ // Create and install our TestAppContentDelegate with instrumentation.
+ test_app_content_delegate_ = new TestAppContentDelegate();
+ AppRegistry::Get()->SetDelegate(test_app_content_delegate_);
+ }
+
+ // A function to create an Activity.
+ TestAppActivity* CreateAppActivity(const std::string& app_id) {
+ TestAppActivity* activity = new TestAppActivity(app_id);
+ ActivityManager::Get()->AddActivity(activity);
+ return activity;
+ }
+
+ protected:
+ TestAppContentDelegate* test_app_content_delegate() {
+ return test_app_content_delegate_;
+ }
+
+ private:
+ TestAppContentDelegate* test_app_content_delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppActivityTest);
+};
+
+// Only creates one activity and destroys it.
+TEST_F(AppActivityTest, OneAppActivity) {
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ {
+ scoped_ptr<TestAppActivity> app_activity(CreateAppActivity(kDummyApp1));
+ EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(1, app_activity->app_activity_registry()->NumberOfActivities());
+ }
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(0, test_app_content_delegate()->unload_called());
+ EXPECT_EQ(0, test_app_content_delegate()->restart_called());
+}
+
+// Test running of two applications.
+TEST_F(AppActivityTest, TwoAppsWithOneActivityEach) {
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ {
+ scoped_ptr<TestAppActivity> app_activity1(CreateAppActivity(kDummyApp1));
+ EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities());
+ scoped_ptr<TestAppActivity> app_activity2(CreateAppActivity(kDummyApp2));
+ EXPECT_EQ(2, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(1, app_activity2->app_activity_registry()->NumberOfActivities());
+ EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities());
+ }
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(0, test_app_content_delegate()->unload_called());
+ EXPECT_EQ(0, test_app_content_delegate()->restart_called());
+}
+
+// Create and destroy two activities for the same application.
+TEST_F(AppActivityTest, TwoAppActivities) {
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ {
+ TestAppActivity* app_activity1 = CreateAppActivity(kDummyApp1);
+ TestAppActivity* app_activity2 = CreateAppActivity(kDummyApp1);
+ EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(2, app_activity1->app_activity_registry()->NumberOfActivities());
+ EXPECT_EQ(app_activity1->app_activity_registry(),
+ app_activity2->app_activity_registry());
+ delete app_activity1;
oshima 2014/08/18 17:51:43 scoped_ptr
Mr4D (OOO till 08-26) 2014/08/18 22:36:31 This is outdated and got already changed.
+ EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(1, app_activity2->app_activity_registry()->NumberOfActivities());
+ delete app_activity2;
+ }
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ {
+ TestAppActivity* app_activity1 = CreateAppActivity(kDummyApp1);
+ TestAppActivity* app_activity2 = CreateAppActivity(kDummyApp1);
+ EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(2, app_activity1->app_activity_registry()->NumberOfActivities());
+ EXPECT_EQ(app_activity1->app_activity_registry(),
+ app_activity2->app_activity_registry());
+ delete app_activity2;
+ EXPECT_EQ(1, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(1, app_activity1->app_activity_registry()->NumberOfActivities());
+ delete app_activity1;
+ }
+ EXPECT_EQ(0, AppRegistry::Get()->NumberOfApplications());
+ EXPECT_EQ(0, test_app_content_delegate()->unload_called());
+ EXPECT_EQ(0, test_app_content_delegate()->restart_called());
+}
+
+// Test unload and the creation of the proxy.
+TEST_F(AppActivityTest, TestUnloadWithoutDestruction) {
+ // TODO.
+}
+
+// Test that when unloading an app while multiple apps / activities are present,
+// the proxy gets created in the correct location.
+TEST_F(AppActivityTest, TestUnloadProxyLocation) {
+ // TODO.
+}
+
+// Test that an unload with multiple activities of the same app will only unload
+// when all activities were marked for unloading.
+TEST_F(AppActivityTest, TestMultipleActivityUnloadLock) {
+ // TODO.
+}
+
+// Test that activating the proxy will reload the application.
+TEST_F(AppActivityTest, TestUnloadWithReload) {
+ // TODO.
+}
+
+} // namespace test
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698