Commit f086a6df authored by oshima's avatar oshima Committed by Commit bot

Orientation request may arrive before the window is created.

Instead of adding another map, I introduced AppWindowInfo which stores information about the arc windows w/o actual window.

Technically, we can move more from AppWindow, but we
can revisit it later if we want.

BUG=31836336
TEST=ChromeLauncherControllerOrientationTest.ArcOrientationLockBeforeWindowReady

Review-Url: https://codereview.chromium.org/2384773002
Cr-Commit-Position: refs/heads/master@{#422635}
parent ee53d147
......@@ -85,18 +85,19 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
private:
class AppWindow;
class AppWindowInfo;
using TaskIdToAppWindow = std::map<int, std::unique_ptr<AppWindow>>;
using TaskIdToShelfAppIdMap = std::map<int, std::string>;
using AppControllerMap =
using TaskIdToAppWindowInfo = std::map<int, std::unique_ptr<AppWindowInfo>>;
using ShelfAppIdToAppControllerMap =
std::map<std::string, ArcAppWindowLauncherItemController*>;
void StartObserving(Profile* profile);
void StopObserving(Profile* profile);
void RegisterApp(AppWindow* app_window);
void UnregisterApp(AppWindow* app_window, bool close_controller);
void RegisterApp(AppWindowInfo* app_window_info);
void UnregisterApp(AppWindowInfo* app_window_info, bool close_controller);
AppWindowInfo* GetAppWindowInfoForTask(int task_id);
AppWindow* GetAppWindowForTask(int task_id);
void AttachControllerToWindowIfNeeded(aura::Window* window);
......@@ -114,9 +115,8 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
// Not owned
ash::ShelfDelegate* shelf_delegate_;
int active_task_id_ = -1;
TaskIdToAppWindow task_id_to_app_window_;
TaskIdToShelfAppIdMap task_id_to_shelf_app_id_;
AppControllerMap app_controller_map_;
TaskIdToAppWindowInfo task_id_to_app_window_info_;
ShelfAppIdToAppControllerMap app_controller_map_;
std::vector<aura::Window*> observed_windows_;
Profile* observed_profile_ = nullptr;
bool observing_shell_ = false;
......
......@@ -3719,6 +3719,57 @@ class ChromeLauncherControllerArcDefaultAppsTest
} // namespace
TEST_F(ChromeLauncherControllerOrientationTest,
ArcOrientationLockBeforeWindowReady) {
ASSERT_TRUE(display::Display::HasInternalDisplay());
extension_service_->AddExtension(arc_support_host_.get());
EnableArc(true);
InitLauncherController();
arc::ArcAuthService::SetShelfDelegateForTesting(launcher_controller_.get());
ash::ScreenOrientationController* controller =
ash::Shell::GetInstance()->screen_orientation_controller();
std::string app_id1("org.chromium.arc.1");
int task_id1 = 1;
arc::mojom::AppInfo appinfo1 =
CreateAppInfo("Test1", "test", "com.example.app", OrientationLock::NONE);
AddArcAppAndShortcut(appinfo1);
NotifyOnTaskCreated(appinfo1, task_id1);
NotifyOnTaskOrientationLockRequested(task_id1, OrientationLock::PORTRAIT);
// Widgets will be deleted by the system.
CreateArcWindow(app_id1);
EXPECT_FALSE(controller->rotation_locked());
EnableTabletMode(true);
EXPECT_TRUE(controller->rotation_locked());
EXPECT_EQ(display::Display::ROTATE_90,
display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
std::string app_id2("org.chromium.arc.2");
int task_id2 = 2;
arc::mojom::AppInfo appinfo2 =
CreateAppInfo("Test2", "test", "com.example.app", OrientationLock::NONE);
// Create in tablet mode.
AddArcAppAndShortcut(appinfo2);
NotifyOnTaskCreated(appinfo2, task_id2);
NotifyOnTaskOrientationLockRequested(task_id2, OrientationLock::LANDSCAPE);
EXPECT_TRUE(controller->rotation_locked());
EXPECT_EQ(display::Display::ROTATE_90,
display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
// The screen will be locked when the window is created.
CreateArcWindow(app_id2);
EXPECT_TRUE(controller->rotation_locked());
EXPECT_EQ(display::Display::ROTATE_0,
display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
}
TEST_F(ChromeLauncherControllerOrientationTest, ArcOrientationLock) {
ASSERT_TRUE(display::Display::HasInternalDisplay());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment