Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / launcher / chrome_launcher_controller_unittest.cc
index b9ae930..599c8c2 100644 (file)
 #include "ui/base/models/menu_model.h"
 
 #if defined(OS_CHROMEOS)
-#include "apps/app_window_contents.h"
-#include "apps/app_window_registry.h"
-#include "apps/ui/native_app_window.h"
 #include "ash/test/test_session_state_delegate.h"
 #include "ash/test/test_shell_delegate.h"
+#include "chrome/browser/apps/scoped_keep_alive.h"
 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
 #include "chrome/browser/ui/apps/chrome_app_delegate.h"
@@ -66,6 +64,9 @@
 #include "chrome/test/base/testing_profile_manager.h"
 #include "content/public/browser/web_contents_observer.h"
 #include "content/public/test/test_utils.h"
+#include "extensions/browser/app_window/app_window_contents.h"
+#include "extensions/browser/app_window/app_window_registry.h"
+#include "extensions/browser/app_window/native_app_window.h"
 #include "ui/aura/window.h"
 #endif
 
@@ -80,9 +81,6 @@ const char* gmail_url = "https://mail.google.com/mail/u";
 const char* kGmailLaunchURL = "https://mail.google.com/mail/ca";
 
 #if defined(OS_CHROMEOS)
-// As defined in /chromeos/dbus/cryptohome_client.cc.
-const char kUserIdHashSuffix[] = "-hash";
-
 // An extension prefix.
 const char kCrxAppPrefix[] = "_crx_";
 #endif
@@ -745,10 +743,14 @@ class V1App : public TestBrowserWindow {
 class V2App {
  public:
   V2App(Profile* profile, const extensions::Extension* extension) {
-    window_ = new apps::AppWindow(profile, new ChromeAppDelegate(), extension);
-    apps::AppWindow::CreateParams params = apps::AppWindow::CreateParams();
-    window_->Init(
-        GURL(std::string()), new apps::AppWindowContentsImpl(window_), params);
+    window_ = new extensions::AppWindow(
+        profile,
+        new ChromeAppDelegate(make_scoped_ptr(new ScopedKeepAlive)),
+        extension);
+    extensions::AppWindow::CreateParams params =
+        extensions::AppWindow::CreateParams();
+    window_->Init(GURL(std::string()),
+                  new extensions::AppWindowContentsImpl(window_), params);
   }
 
   virtual ~V2App() {
@@ -757,13 +759,13 @@ class V2App {
     destroyed_watcher.Wait();
   }
 
-  apps::AppWindow* window() { return window_; }
+  extensions::AppWindow* window() { return window_; }
 
  private:
   // The app window which represents the application. Note that the window
   // deletes itself asynchronously after window_->GetBaseWindow()->Close() gets
   // called.
-  apps::AppWindow* window_;
+  extensions::AppWindow* window_;
 
   DISALLOW_COPY_AND_ASSIGN(V2App);
 };
@@ -827,22 +829,14 @@ class MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest
     session_delegate()->AddUser(email_string);
     GetFakeUserManager()->AddUser(email_string);
 
-    GetFakeUserManager()->UserLoggedIn(
-        email_string,
-        email_string + kUserIdHashSuffix,
-        false);
-
-    std::string profile_name =
-        chrome::kProfileDirPrefix + email_string + kUserIdHashSuffix;
-    TestingProfile* profile = profile_manager()->CreateTestingProfile(
-        profile_name,
-        scoped_ptr<PrefServiceSyncable>(),
-        ASCIIToUTF16(email_string), 0, std::string(),
-        TestingProfile::TestingFactories());
-    profile->set_profile_name(email_string);
+    GetFakeUserManager()->LoginUser(email_string);
+
+    TestingProfile* profile =
+        profile_manager()->CreateTestingProfile(email_string);
     EXPECT_TRUE(profile);
+
     // Remember the profile name so that we can destroy it upon destruction.
-    created_profiles_[profile] = profile_name;
+    created_profiles_[profile] = email_string;
     if (chrome::MultiUserWindowManager::GetInstance())
       chrome::MultiUserWindowManager::GetInstance()->AddUser(profile);
     if (launcher_controller_)
@@ -2189,7 +2183,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
   EXPECT_EQ(2, model_->item_count());
 
   // Add a v2 app.
-  V2App v2_app(profile(), extension1_);
+  V2App v2_app(profile(), extension1_.get());
   EXPECT_EQ(3, model_->item_count());
 
   // After switching users the item should go away.
@@ -2219,7 +2213,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
   // Add the v2 app to the inactive user and check that no item was added to
   // the launcher.
   {
-    V2App v2_app(profile(), extension1_);
+    V2App v2_app(profile(), extension1_.get());
     EXPECT_EQ(2, model_->item_count());
 
     // Switch to the primary user and check that the item is shown.
@@ -2257,13 +2251,13 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
 
   // A v2 app for user #1 should be shown first and get hidden when switching to
   // desktop #2.
-  V2App v2_app_1(profile1, extension1_);
+  V2App v2_app_1(profile1, extension1_.get());
   EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
   SwitchActiveUser(profile2->GetProfileName());
   EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
 
   // Add a v2 app for user #1 while on desktop #2 should not be shown.
-  V2App v2_app_2(profile1, extension1_);
+  V2App v2_app_2(profile1, extension1_.get());
   EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
   EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
 
@@ -2275,7 +2269,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
 
   // Creating a new application for user #1 on desktop #2 should teleport it
   // there automatically.
-  V2App v2_app_3(profile1, extension1_);
+  V2App v2_app_3(profile1, extension1_.get());
   EXPECT_TRUE(v2_app_1.window()->GetNativeWindow()->IsVisible());
   EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
   EXPECT_TRUE(v2_app_3.window()->GetNativeWindow()->IsVisible());
@@ -2283,7 +2277,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
   // Switching back to desktop#1 and creating an app for user #1 should move
   // the app on desktop #1.
   SwitchActiveUser(profile1->GetProfileName());
-  V2App v2_app_4(profile1, extension1_);
+  V2App v2_app_4(profile1, extension1_.get());
   EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
   EXPECT_TRUE(v2_app_2.window()->GetNativeWindow()->IsVisible());
   EXPECT_FALSE(v2_app_3.window()->GetNativeWindow()->IsVisible());
@@ -2292,7 +2286,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
   // Switching to desktop #3 and create an app for user #1 there should land on
   // his own desktop (#1).
   SwitchActiveUser(profile3->GetProfileName());
-  V2App v2_app_5(profile1, extension1_);
+  V2App v2_app_5(profile1, extension1_.get());
   EXPECT_FALSE(v2_app_5.window()->GetNativeWindow()->IsVisible());
   SwitchActiveUser(profile1->GetProfileName());
   EXPECT_TRUE(v2_app_5.window()->GetNativeWindow()->IsVisible());
@@ -2301,7 +2295,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
   // teleport there automatically.
   SwitchActiveUser(profile2->GetProfileName());
   v2_app_1.window()->Hide();
-  V2App v2_app_6(profile1, extension1_);
+  V2App v2_app_6(profile1, extension1_.get());
   EXPECT_FALSE(v2_app_1.window()->GetNativeWindow()->IsVisible());
   EXPECT_FALSE(v2_app_2.window()->GetNativeWindow()->IsVisible());
   EXPECT_TRUE(v2_app_6.window()->GetNativeWindow()->IsVisible());
@@ -2317,14 +2311,14 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
   SwitchActiveUser(profile()->GetProfileName());
   EXPECT_EQ(2, model_->item_count());
 
-  V2App v2_app_1(profile(), extension1_);
+  V2App v2_app_1(profile(), extension1_.get());
   EXPECT_EQ(3, model_->item_count());
   {
     // Hide and show the app.
     v2_app_1.window()->Hide();
     EXPECT_EQ(2, model_->item_count());
 
-    v2_app_1.window()->Show(apps::AppWindow::SHOW_ACTIVE);
+    v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
     EXPECT_EQ(3, model_->item_count());
   }
   {
@@ -2335,7 +2329,7 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
     v2_app_1.window()->Hide();
     EXPECT_EQ(2, model_->item_count());
 
-    v2_app_1.window()->Show(apps::AppWindow::SHOW_ACTIVE);
+    v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
     EXPECT_EQ(2, model_->item_count());
 
     SwitchActiveUser(profile()->GetProfileName());
@@ -2352,18 +2346,18 @@ TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
     SwitchActiveUser(profile()->GetProfileName());
     EXPECT_EQ(2, model_->item_count());
 
-    v2_app_1.window()->Show(apps::AppWindow::SHOW_ACTIVE);
+    v2_app_1.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
     EXPECT_EQ(3, model_->item_count());
   }
   {
     // Create a second app, hide and show it and then hide both apps.
-    V2App v2_app_2(profile(), extension1_);
+    V2App v2_app_2(profile(), extension1_.get());
     EXPECT_EQ(3, model_->item_count());
 
     v2_app_2.window()->Hide();
     EXPECT_EQ(3, model_->item_count());
 
-    v2_app_2.window()->Show(apps::AppWindow::SHOW_ACTIVE);
+    v2_app_2.window()->Show(extensions::AppWindow::SHOW_ACTIVE);
     EXPECT_EQ(3, model_->item_count());
 
     v2_app_1.window()->Hide();