146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)/// Copyright 2014 The Chromium Authors. All rights reserved.
246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// found in the LICENSE file.
446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/activity/activity_manager_impl.h"
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "athena/activity/public/activity.h"
846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "athena/activity/public/activity_factory.h"
946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "athena/test/athena_test_base.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/aura/window.h"
1146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace athena {
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitypedef test::AthenaTestBase ActivityManagerTest;
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST_F(ActivityManagerTest, Basic) {
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ActivityManagerImpl* activity_manager =
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      static_cast<ActivityManagerImpl*>(ActivityManager::Get());
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ActivityFactory* factory = ActivityFactory::Get();
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Activity* activity1 =
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      factory->CreateWebActivity(NULL, base::string16(), GURL());
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, activity_manager->num_activities());
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Activity is not visible when created.
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_FALSE(activity1->GetWindow()->TargetVisibility());
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Activity::Show(activity1);
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_TRUE(activity1->GetWindow()->TargetVisibility());
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Activity* activity2 =
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      factory->CreateWebActivity(NULL, base::string16(), GURL());
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(2, activity_manager->num_activities());
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Activity::Delete(activity1);
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, activity_manager->num_activities());
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Deleting the activity's window should delete the activity itself.
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  delete activity2->GetWindow();
391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(0, activity_manager->num_activities());
4046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciTEST_F(ActivityManagerTest, GetActivityForWindow) {
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ActivityManager* manager = ActivityManager::Get();
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ActivityFactory* factory = ActivityFactory::Get();
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Activity* activity1 =
471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      factory->CreateWebActivity(NULL, base::string16(), GURL());
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Activity* activity2 =
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      factory->CreateWebActivity(NULL, base::string16(), GURL());
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(activity1, manager->GetActivityForWindow(activity1->GetWindow()));
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(activity2, manager->GetActivityForWindow(activity2->GetWindow()));
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(NULL, manager->GetActivityForWindow(NULL));
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect());
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(NULL, manager->GetActivityForWindow(window.get()));
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}  // namespace athena
61