This source file includes following definitions.
- waiting_
- WaitForEntirelyChanged
- OnGeometryCacheChanged
- RunAppWindowAPITest
- RunAppWindowAPITestAndWaitForRoundTrip
- BeginAppWindowAPITest
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#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 "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
using apps::AppWindowGeometryCache;
class GeometryCacheChangeHelper : AppWindowGeometryCache::Observer {
public:
GeometryCacheChangeHelper(AppWindowGeometryCache* cache,
const std::string& extension_id,
const std::string& window_id,
const gfx::Rect& bounds)
: cache_(cache),
extension_id_(extension_id),
window_id_(window_id),
bounds_(bounds),
satisfied_(false),
waiting_(false) {
cache_->AddObserver(this);
}
void WaitForEntirelyChanged() {
if (satisfied_)
return;
waiting_ = true;
content::RunMessageLoop();
}
virtual void OnGeometryCacheChanged(const std::string& extension_id,
const std::string& window_id,
const gfx::Rect& bounds)
OVERRIDE {
if (extension_id != extension_id_ || window_id != window_id_)
return;
if (bounds_.x() != bounds.x() &&
bounds_.y() != bounds.y() &&
bounds_.width() != bounds.width() &&
bounds_.height() != bounds.height()) {
satisfied_ = true;
cache_->RemoveObserver(this);
if (waiting_)
base::MessageLoopForUI::current()->Quit();
}
}
private:
AppWindowGeometryCache* cache_;
std::string extension_id_;
std::string window_id_;
gfx::Rect bounds_;
bool satisfied_;
bool waiting_;
};
class AppWindowAPITest : public extensions::PlatformAppBrowserTest {
protected:
bool RunAppWindowAPITest(const char* testName) {
if (!BeginAppWindowAPITest(testName))
return false;
ResultCatcher catcher;
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;
}
};
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestCreate) {
ASSERT_TRUE(RunAppWindowAPITest("testCreate")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestSingleton) {
ASSERT_TRUE(RunAppWindowAPITest("testSingleton")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestCloseEvent) {
ASSERT_TRUE(RunAppWindowAPITest("testCloseEvent")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, DISABLED_TestMaximize) {
ASSERT_TRUE(RunAppWindowAPITest("testMaximize")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, DISABLED_TestRestore) {
ASSERT_TRUE(RunAppWindowAPITest("testRestore")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, DISABLED_TestRestoreAfterClose) {
ASSERT_TRUE(RunAppWindowAPITest("testRestoreAfterClose")) << message_;
}
#if defined(OS_LINUX)
#define MAYBE_TestDeprecatedBounds DISABLED_TestDeprecatedBounds
#define MAYBE_TestInitialBounds DISABLED_TestInitialBounds
#define MAYBE_TestInitialConstraints DISABLED_TestInitialConstraints
#define MAYBE_TestSetBounds DISABLED_TestSetBounds
#define MAYBE_TestSetSizeConstraints DISABLED_TestSetSizeConstraints
#else
#define MAYBE_TestDeprecatedBounds TestDeprecatedBounds
#define MAYBE_TestInitialBounds TestInitialBounds
#define MAYBE_TestInitialConstraints TestInitialConstraints
#define MAYBE_TestSetBounds TestSetBounds
#define MAYBE_TestSetSizeConstraints TestSetSizeConstraints
#endif
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, MAYBE_TestDeprecatedBounds) {
ASSERT_TRUE(RunAppWindowAPITest("testDeprecatedBounds")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, MAYBE_TestInitialBounds) {
ASSERT_TRUE(RunAppWindowAPITest("testInitialBounds")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, MAYBE_TestInitialConstraints) {
ASSERT_TRUE(RunAppWindowAPITest("testInitialConstraints")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, MAYBE_TestSetBounds) {
ASSERT_TRUE(RunAppWindowAPITest("testSetBounds")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, MAYBE_TestSetSizeConstraints) {
ASSERT_TRUE(RunAppWindowAPITest("testSetSizeConstraints")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestNewBoundsApiInStable) {
extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
ASSERT_TRUE(RunAppWindowAPITest("testNewBoundsApiInStable")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest,
DISABLED_TestRestoreGeometryCacheChange) {
ExtensionTestMessageListener launched_listener("Launched", true);
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
const extensions::Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("platform_apps").AppendASCII("window_api"));
EXPECT_TRUE(extension);
OpenApplication(AppLaunchParams(browser()->profile(),
extension,
extensions::LAUNCH_CONTAINER_NONE,
NEW_WINDOW));
ExtensionTestMessageListener geometry_listener("ListenGeometryChange", true);
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
launched_listener.Reply("testRestoreAfterGeometryCacheChange");
ASSERT_TRUE(geometry_listener.WaitUntilSatisfied());
GeometryCacheChangeHelper geo_change_helper_1(
AppWindowGeometryCache::Get(browser()->profile()),
extension->id(),
"test-ra",
gfx::Rect(200, 200, 200, 200));
GeometryCacheChangeHelper geo_change_helper_2(
AppWindowGeometryCache::Get(browser()->profile()),
extension->id(),
"test-rb",
gfx::Rect(200, 200, 200, 200));
geo_change_helper_1.WaitForEntirelyChanged();
geo_change_helper_2.WaitForEntirelyChanged();
ResultCatcher catcher;
geometry_listener.Reply("");
ASSERT_TRUE(catcher.GetNextResult());
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestBadging) {
ASSERT_TRUE(
RunAppWindowAPITestAndWaitForRoundTrip("testBadging")) << message_;
}
#if defined(USE_AURA)
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestFrameColors) {
ASSERT_TRUE(RunAppWindowAPITest("testFrameColors")) << message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowAPITest, TestFrameColorsInStable) {
extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE);
ASSERT_TRUE(RunAppWindowAPITest("testFrameColorsInStable")) << message_;
}
#endif