summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsadrul <sadrul@chromium.org>2015-08-06 22:25:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-07 05:25:58 +0000
commit679eb98faedae0b02df52e287e8180728f0b0fbd (patch)
tree338ee8c4ef6d7eb4434717ae9243a664d95fa615 /ash
parentd9c347b62ded29ffb33cc864dc44fc60a0708539 (diff)
downloadchromium_src-679eb98faedae0b02df52e287e8180728f0b0fbd.zip
chromium_src-679eb98faedae0b02df52e287e8180728f0b0fbd.tar.gz
chromium_src-679eb98faedae0b02df52e287e8180728f0b0fbd.tar.bz2
aura: Sanitize the lifetime of aura::Env instance.
Currently, the aura::Env instance is created and/or destroyed from unexpected places (e.g. WebContentsViewAura), and that makes it difficult to reason about its lifetime. This patch tries to make this better. Notable changes: . Instead of having the ash::Shell instance be responsible for creating the aura::Env instance, make the creator of the Shell instance be responsible for also creating the aura::Env instance. . Individual TestSuite instances are responsible for managing the aura::Env instance for the tests (content::UnitTestTestSuite, ash::AuraShellTestSuite) . For chrome and browser-tests, the browser main-loop is responsible for managing the aura::Env instance. . For interactive-ui-tests that do not use the browser main-loop, each test explicitly manages its aura::Env instance. BUG=515031, 516898 TBR=avi@ for trivial change in content/browser/ Review URL: https://codereview.chromium.org/1270173004 Cr-Commit-Position: refs/heads/master@{#342300}
Diffstat (limited to 'ash')
-rw-r--r--ash/accelerators/accelerator_interactive_uitest_chromeos.cc3
-rw-r--r--ash/drag_drop/drag_drop_interactive_uitest.cc7
-rw-r--r--ash/shell.cc2
-rw-r--r--ash/test/ash_test_helper.cc2
-rw-r--r--ash/test/test_suite.cc3
-rw-r--r--ash/wm/ash_native_cursor_manager_interactive_uitest.cc7
6 files changed, 21 insertions, 3 deletions
diff --git a/ash/accelerators/accelerator_interactive_uitest_chromeos.cc b/ash/accelerators/accelerator_interactive_uitest_chromeos.cc
index a776229..3babbc5 100644
--- a/ash/accelerators/accelerator_interactive_uitest_chromeos.cc
+++ b/ash/accelerators/accelerator_interactive_uitest_chromeos.cc
@@ -17,6 +17,7 @@
#include "base/path_service.h"
#include "base/run_loop.h"
#include "chromeos/network/network_handler.h"
+#include "ui/aura/env.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/test/ui_controls.h"
#include "ui/base/ui_base_paths.h"
@@ -69,6 +70,7 @@ class AcceleratorInteractiveUITest : public AshTestBase, public ShellObserver {
resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
resources_pack_path, ui::SCALE_FACTOR_NONE);
+ aura::Env::CreateInstance(true);
AshTestBase::SetUp();
@@ -83,6 +85,7 @@ class AcceleratorInteractiveUITest : public AshTestBase, public ShellObserver {
Shell::GetInstance()->RemoveShellObserver(this);
AshTestBase::TearDown();
+ aura::Env::DeleteInstance();
}
// Sends a key press event and waits synchronously until it's completely
diff --git a/ash/drag_drop/drag_drop_interactive_uitest.cc b/ash/drag_drop/drag_drop_interactive_uitest.cc
index b8968dcd..91d34ac 100644
--- a/ash/drag_drop/drag_drop_interactive_uitest.cc
+++ b/ash/drag_drop/drag_drop_interactive_uitest.cc
@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
+#include "ui/aura/env.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/resource/resource_bundle.h"
@@ -134,9 +135,15 @@ class DragDropTest : public test::AshTestBase {
resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
resources_pack_path, ui::SCALE_FACTOR_NONE);
+ aura::Env::CreateInstance(true);
test::AshTestBase::SetUp();
}
+
+ void TearDown() override {
+ test::AshTestBase::TearDown();
+ aura::Env::DeleteInstance();
+ }
};
#if !defined(OS_CHROMEOS)
diff --git a/ash/shell.cc b/ash/shell.cc
index 4cbc6d4..ef36860 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -647,6 +647,7 @@ Shell::Shell(ShellDelegate* delegate)
simulate_modal_window_open_for_testing_(false),
is_touch_hud_projection_enabled_(false) {
DCHECK(delegate_.get());
+ DCHECK(aura::Env::GetInstanceDontCreate());
gpu_support_.reset(delegate_->CreateGPUSupport());
display_manager_.reset(new DisplayManager);
window_tree_host_manager_.reset(new WindowTreeHostManager);
@@ -881,7 +882,6 @@ void Shell::Init(const ShellInitParams& init_params) {
// Shelf, and WallPaper could be created by the factory.
views::FocusManagerFactory::Install(new AshFocusManagerFactory);
- aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
// The WindowModalityController needs to be at the front of the input event
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index 22f16bb..177f3ad 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -128,7 +128,6 @@ void AshTestHelper::TearDown() {
}
#endif
- aura::Env::DeleteInstance();
ui::TerminateContextFactoryForTests();
// Need to reset the initial login status.
@@ -144,7 +143,6 @@ void AshTestHelper::TearDown() {
void AshTestHelper::RunAllPendingInMessageLoop() {
DCHECK(base::MessageLoopForUI::current() == message_loop_);
- aura::Env::CreateInstance(true);
base::RunLoop run_loop;
run_loop.RunUntilIdle();
}
diff --git a/ash/test/test_suite.cc b/ash/test/test_suite.cc
index 73de7b3..c39c76b 100644
--- a/ash/test/test_suite.cc
+++ b/ash/test/test_suite.cc
@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/aura/env.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/gfx/gfx_paths.h"
@@ -58,9 +59,11 @@ void AuraShellTestSuite::Initialize() {
"en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
+ aura::Env::CreateInstance(true);
}
void AuraShellTestSuite::Shutdown() {
+ aura::Env::DeleteInstance();
ui::ResourceBundle::CleanupSharedInstance();
#if defined(OS_WIN)
com_initializer_.reset();
diff --git a/ash/wm/ash_native_cursor_manager_interactive_uitest.cc b/ash/wm/ash_native_cursor_manager_interactive_uitest.cc
index a7d0536..214394b 100644
--- a/ash/wm/ash_native_cursor_manager_interactive_uitest.cc
+++ b/ash/wm/ash_native_cursor_manager_interactive_uitest.cc
@@ -10,6 +10,7 @@
#include "ash/test/cursor_manager_test_api.h"
#include "base/path_service.h"
#include "base/run_loop.h"
+#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/resource/resource_bundle.h"
@@ -42,9 +43,15 @@ class AshNativeCursorManagerTest : public test::AshTestBase {
resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
ResourceBundle::GetSharedInstance().AddDataPackFromPath(
resources_pack_path, ui::SCALE_FACTOR_NONE);
+ aura::Env::CreateInstance(true);
test::AshTestBase::SetUp();
}
+
+ void TearDown() override {
+ test::AshTestBase::TearDown();
+ aura::Env::DeleteInstance();
+ }
};
namespace {