Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / apps / app_window_browsertest.cc
index eec45fa..234ee3f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "apps/shell_window_geometry_cache.h"
+#include "apps/app_window_geometry_cache.h"
 #include "chrome/browser/apps/app_browsertest_util.h"
 #include "chrome/browser/extensions/extension_test_message_listener.h"
 #include "chrome/browser/profiles/profile.h"
 #include "extensions/common/constants.h"
 #include "extensions/common/extension.h"
 
-using apps::ShellWindowGeometryCache;
+using apps::AppWindowGeometryCache;
 
-// This helper class can be used to wait for changes in the shell window
+// This helper class can be used to wait for changes in the app window
 // geometry cache registry for a specific window in a specific extension.
-class GeometryCacheChangeHelper : ShellWindowGeometryCache::Observer {
+class GeometryCacheChangeHelper : AppWindowGeometryCache::Observer {
  public:
-  GeometryCacheChangeHelper(ShellWindowGeometryCache* cache,
+  GeometryCacheChangeHelper(AppWindowGeometryCache* cache,
                             const std::string& extension_id,
                             const std::string& window_id,
                             const gfx::Rect& bounds)
@@ -32,7 +32,7 @@ class GeometryCacheChangeHelper : ShellWindowGeometryCache::Observer {
     cache_->AddObserver(this);
   }
 
-  // This method will block until the shell window geometry cache registry will
+  // This method will block until the app window geometry cache registry will
   // provide a bound for |window_id_| that is entirely different (as in x/y/w/h)
   // from the initial |bounds_|.
   void WaitForEntirelyChanged() {
@@ -64,7 +64,7 @@ class GeometryCacheChangeHelper : ShellWindowGeometryCache::Observer {
   }
 
  private:
-  ShellWindowGeometryCache* cache_;
+  AppWindowGeometryCache* cache_;
   std::string extension_id_;
   std::string window_id_;
   gfx::Rect bounds_;
@@ -74,18 +74,33 @@ class GeometryCacheChangeHelper : ShellWindowGeometryCache::Observer {
 
 // Helper class for tests related to the Apps Window API (chrome.app.window).
 class AppWindowAPITest : public extensions::PlatformAppBrowserTest {
- public:
+ protected:
   bool RunAppWindowAPITest(const char* testName) {
-    ExtensionTestMessageListener launched_listener("Launched", true);
-    LoadAndLaunchPlatformApp("window_api");
-    if (!launched_listener.WaitUntilSatisfied()) {
-      message_ = "Did not get the 'Launched' message.";
+    if (!BeginAppWindowAPITest(testName))
       return false;
-    }
 
     ResultCatcher catcher;
-    launched_listener.Reply(testName);
+    if (!catcher.GetNextResult()) {
+      message_ = catcher.message();
+      return false;
+    }
+
+    return true;
+  }
 
+  bool RunAppWindowAPITestAndWaitForRoundTrip(const char* testName) {
+    if (!BeginAppWindowAPITest(testName))
+      return false;
+
+    ExtensionTestMessageListener round_trip_listener("WaitForRoundTrip", true);
+    if (!round_trip_listener.WaitUntilSatisfied()) {
+      message_ = "Did not get the 'WaitForRoundTrip' message.";
+      return false;
+    }
+
+    round_trip_listener.Reply("");
+
+    ResultCatcher catcher;
     if (!catcher.GetNextResult()) {
       message_ = catcher.message();
       return false;
@@ -93,6 +108,19 @@ class AppWindowAPITest : public extensions::PlatformAppBrowserTest {
 
     return true;
   }
+
+ private:
+  bool BeginAppWindowAPITest(const char* testName) {
+    ExtensionTestMessageListener launched_listener("Launched", true);
+    LoadAndLaunchPlatformApp("window_api");
+    if (!launched_listener.WaitUntilSatisfied()) {
+      message_ = "Did not get the 'Launched' message.";
+      return false;
+    }
+
+    launched_listener.Reply(testName);
+    return true;
+  }
 };
 
 // These tests are flaky after https://codereview.chromium.org/57433010/.
@@ -161,16 +189,20 @@ IN_PROC_BROWSER_TEST_F(AppWindowAPITest,
   ASSERT_TRUE(geometry_listener.WaitUntilSatisfied());
 
   GeometryCacheChangeHelper geo_change_helper_1(
-      ShellWindowGeometryCache::Get(browser()->profile()), extension->id(),
+      AppWindowGeometryCache::Get(browser()->profile()),
+      extension->id(),
       // The next line has information that has to stay in sync with the app.
-      "test-ra", gfx::Rect(200, 200, 200, 200));
+      "test-ra",
+      gfx::Rect(200, 200, 200, 200));
 
   GeometryCacheChangeHelper geo_change_helper_2(
-      ShellWindowGeometryCache::Get(browser()->profile()), extension->id(),
+      AppWindowGeometryCache::Get(browser()->profile()),
+      extension->id(),
       // The next line has information that has to stay in sync with the app.
-      "test-rb", gfx::Rect(200, 200, 200, 200));
+      "test-rb",
+      gfx::Rect(200, 200, 200, 200));
 
-  // These calls will block until the shell window geometry cache will change.
+  // These calls will block until the app window geometry cache will change.
   geo_change_helper_1.WaitForEntirelyChanged();
   geo_change_helper_2.WaitForEntirelyChanged();
 
@@ -178,3 +210,8 @@ IN_PROC_BROWSER_TEST_F(AppWindowAPITest,
   geometry_listener.Reply("");
   ASSERT_TRUE(catcher.GetNextResult());
 }
+
+IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestBadging) {
+  ASSERT_TRUE(
+      RunAppWindowAPITestAndWaitForRoundTrip("testBadging")) << message_;
+}