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..36b4e308ce1c73cf011a259e6b84396004421bb9 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,10 +123,7 @@ 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), |
- rendered_page_count_(0) { |
+ ScopedPreviewTestingDelegate() { |
PrintPreviewUI::SetDelegateForTesting(this); |
} |
@@ -135,9 +132,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 +141,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 +160,9 @@ class ScopedPreviewTestingDelegate : PrintPreviewUI::TestingDelegate { |
} |
private: |
- bool auto_cancel_; |
- int total_page_count_; |
- int rendered_page_count_; |
- scoped_refptr<content::MessageLoopRunner> waiting_runner_; |
+ int total_page_count_ = 1; |
+ int rendered_page_count_ = 0; |
+ base::RunLoop* run_loop_ = nullptr; |
gfx::Size dialog_size_; |
}; |
@@ -1138,17 +1131,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 +1141,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 +1163,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(), |