// 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)
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() {
}
private:
- ShellWindowGeometryCache* cache_;
+ AppWindowGeometryCache* cache_;
std::string extension_id_;
std::string window_id_;
gfx::Rect bounds_;
// 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;
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/.
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();
geometry_listener.Reply("");
ASSERT_TRUE(catcher.GetNextResult());
}
+
+IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestBadging) {
+ ASSERT_TRUE(
+ RunAppWindowAPITestAndWaitForRoundTrip("testBadging")) << message_;
+}