Chromium Code Reviews| Index: chrome/browser/apps/app_browsertest.cc |
| diff --git a/chrome/browser/apps/app_browsertest.cc b/chrome/browser/apps/app_browsertest.cc |
| index 823407a55ff5a8ba33608c39f08053874a82dd43..3140539c7cd9133ca13f1f2d05c0304e105ee4f8 100644 |
| --- a/chrome/browser/apps/app_browsertest.cc |
| +++ b/chrome/browser/apps/app_browsertest.cc |
| @@ -7,6 +7,7 @@ |
| #include <memory> |
| #include "apps/launcher.h" |
| +#include "base/auto_reset.h" |
| #include "base/bind.h" |
| #include "base/command_line.h" |
| #include "base/files/file_util.h" |
| @@ -42,7 +43,6 @@ |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/test/browser_test_utils.h" |
| -#include "content/public/test/test_utils.h" |
| #include "extensions/browser/app_window/app_window.h" |
| #include "extensions/browser/app_window/app_window_registry.h" |
| #include "extensions/browser/app_window/native_app_window.h" |
| @@ -123,9 +123,8 @@ class TabsAddedNotificationObserver |
| #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { |
| public: |
| - explicit ScopedPreviewTestingDelegate(bool auto_cancel) |
| - : auto_cancel_(auto_cancel), |
| - total_page_count_(1), |
| + ScopedPreviewTestingDelegate() |
| + : total_page_count_(1), |
| rendered_page_count_(0) { |
| PrintPreviewUI::SetDelegateForTesting(this); |
| } |
| @@ -135,9 +134,6 @@ class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { |
| } |
| // PrintPreviewUI::TestingDelegate implementation. |
| - bool IsAutoCancelEnabled() override { return auto_cancel_; } |
| - |
| - // PrintPreviewUI::TestingDelegate implementation. |
| void DidGetPreviewPageCount(int page_count) override { |
| total_page_count_ = page_count; |
| } |
| @@ -147,18 +143,18 @@ class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { |
| dialog_size_ = preview_dialog->GetContainerBounds().size(); |
| ++rendered_page_count_; |
| CHECK(rendered_page_count_ <= total_page_count_); |
| - if (waiting_runner_.get() && rendered_page_count_ == total_page_count_) { |
| - waiting_runner_->Quit(); |
| + if (rendered_page_count_ == total_page_count_ && run_loop_) { |
| + run_loop_->Quit(); |
| } |
| } |
| void WaitUntilPreviewIsReady() { |
| - CHECK(!waiting_runner_.get()); |
| - if (rendered_page_count_ < total_page_count_) { |
| - waiting_runner_ = new content::MessageLoopRunner; |
| - waiting_runner_->Run(); |
| - waiting_runner_ = NULL; |
| - } |
| + if (rendered_page_count_ >= total_page_count_) |
| + return; |
| + |
| + base::RunLoop run_loop; |
| + base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop); |
| + run_loop.Run(); |
| } |
| gfx::Size dialog_size() { |
| @@ -166,10 +162,9 @@ class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { |
| } |
| private: |
| - bool auto_cancel_; |
| int total_page_count_; |
|
tapted
2017/02/09 02:03:02
nit: move the = 1 down here (and = 0 below) rather
rbpotter
2017/02/09 20:11:46
Done.
|
| int rendered_page_count_; |
| - scoped_refptr<content::MessageLoopRunner> waiting_runner_; |
| + base::RunLoop* run_loop_ = nullptr; |
| gfx::Size dialog_size_; |
| }; |
| @@ -1138,17 +1133,9 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DISABLED_WebContentsHasFocus) { |
| #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| -#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| -#define MAYBE_WindowDotPrintShouldBringUpPrintPreview \ |
| - DISABLED_WindowDotPrintShouldBringUpPrintPreview |
| -#else |
| -#define MAYBE_WindowDotPrintShouldBringUpPrintPreview \ |
| - WindowDotPrintShouldBringUpPrintPreview |
| -#endif |
| - |
| IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| - MAYBE_WindowDotPrintShouldBringUpPrintPreview) { |
| - ScopedPreviewTestingDelegate preview_delegate(true); |
| + WindowDotPrintShouldBringUpPrintPreview) { |
| + ScopedPreviewTestingDelegate preview_delegate; |
| ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
| preview_delegate.WaitUntilPreviewIsReady(); |
| } |
| @@ -1156,7 +1143,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| // This test verifies that http://crbug.com/297179 is fixed. |
| IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| DISABLED_ClosingWindowWhilePrintingShouldNotCrash) { |
| - ScopedPreviewTestingDelegate preview_delegate(false); |
| + ScopedPreviewTestingDelegate preview_delegate; |
| ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
| preview_delegate.WaitUntilPreviewIsReady(); |
| GetFirstAppWindow()->GetBaseWindow()->Close(); |
| @@ -1178,7 +1165,7 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
| // areas that are too small, and ones with heights less than 191 pixels will |
| // have vertical scrollers for their controls that are too small. |
| gfx::Size minimum_dialog_size(410, 191); |
| - ScopedPreviewTestingDelegate preview_delegate(false); |
| + ScopedPreviewTestingDelegate preview_delegate; |
| ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_; |
| preview_delegate.WaitUntilPreviewIsReady(); |
| EXPECT_GE(preview_delegate.dialog_size().width(), |