summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/apps/app_browsertest.cc30
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_ui.cc18
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_ui.h4
-rw-r--r--chrome/test/data/extensions/platform_apps/print_api/manifest.json11
-rw-r--r--chrome/test/data/extensions/platform_apps/print_api/test.html10
-rw-r--r--chrome/test/data/extensions/platform_apps/print_api/test.js17
6 files changed, 88 insertions, 2 deletions
diff --git a/chrome/browser/apps/app_browsertest.cc b/chrome/browser/apps/app_browsertest.cc
index ec4a1a5..4f73818 100644
--- a/chrome/browser/apps/app_browsertest.cc
+++ b/chrome/browser/apps/app_browsertest.cc
@@ -31,6 +31,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/app_runtime.h"
#include "chrome/common/pref_names.h"
@@ -1036,6 +1037,35 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_WebContentsHasFocus) {
GetRenderWidgetHostView()->HasFocus());
}
+class PlatformAppPrintBrowserTest : public extensions::PlatformAppBrowserTest {
+ public:
+ PlatformAppPrintBrowserTest() {}
+
+ // Ensures print tests use the print preview panel even for non-Chrome
+ // branded Chromium builds.
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ command_line->AppendSwitch(switches::kEnablePrintPreview);
+ PlatformAppBrowserTest::SetUpCommandLine(command_line);
+ }
+};
+
+// Currently this test only works if the PDF preview plug-in is available. This
+// plug-in will only be available in Chrome release builds or if it has been
+// manually copied from a Chrome release build. To run this test when the
+// plug-in has been manually copied, manually comment out the next three lines
+// and the corresponding #endif.
+#if !defined(GOOGLE_CHROME_BUILD)
+#define MAYBE_WindowDotPrintWorks DISABLED_WindowDotPrintWorks
+#else
+#define MAYBE_WindowDotPrintWorks WindowDotPrintWorks
+#endif
+
+IN_PROC_BROWSER_TEST_F(PlatformAppPrintBrowserTest, MAYBE_WindowDotPrintWorks) {
+ PrintPreviewUI::SetAutoCancelForTesting(true);
+ ASSERT_TRUE(RunPlatformAppTest("platform_apps/print_api")) << message_;
+ PrintPreviewUI::SetAutoCancelForTesting(false);
+}
+
#if defined(OS_CHROMEOS)
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview/print_preview_ui.cc
index ca4c7e4..4e8e8ab 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_ui.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_ui.cc
@@ -520,8 +520,12 @@ void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
}
base::FundamentalValue ui_identifier(id_);
base::FundamentalValue ui_preview_request_id(preview_request_id);
- web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier,
- ui_preview_request_id);
+ if (AutoCancelForTesting()) {
+ OnClosePrintPreviewDialog();
+ } else {
+ web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier,
+ ui_preview_request_id);
+ }
}
void PrintPreviewUI::OnPrintPreviewDialogDestroyed() {
@@ -582,3 +586,13 @@ void PrintPreviewUI::OnReloadPrintersList() {
void PrintPreviewUI::OnPrintPreviewScalingDisabled() {
web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF");
}
+
+static bool g_auto_cancel_for_testing_ = false;
+
+void PrintPreviewUI::SetAutoCancelForTesting(bool auto_cancel) {
+ g_auto_cancel_for_testing_ = auto_cancel;
+}
+
+bool PrintPreviewUI::AutoCancelForTesting() {
+ return g_auto_cancel_for_testing_;
+}
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_ui.h b/chrome/browser/ui/webui/print_preview/print_preview_ui.h
index 1cd81e3..c54edbc 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_ui.h
+++ b/chrome/browser/ui/webui/print_preview/print_preview_ui.h
@@ -147,6 +147,10 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// default.
void OnPrintPreviewScalingDisabled();
+ // Manages the global auto-cancel mode used only for testing.
+ static void SetAutoCancelForTesting(bool auto_cancel);
+ static bool AutoCancelForTesting();
+
private:
friend class PrintPreviewHandlerTest;
FRIEND_TEST_ALL_PREFIXES(PrintPreviewHandlerTest, StickyMarginsCustom);
diff --git a/chrome/test/data/extensions/platform_apps/print_api/manifest.json b/chrome/test/data/extensions/platform_apps/print_api/manifest.json
new file mode 100644
index 0000000..96cfd3e
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/print_api/manifest.json
@@ -0,0 +1,11 @@
+{
+ "name": "Platform App Test: window.print() API",
+ "version": "1",
+ "app": {
+ "background": {
+ "scripts": [
+ "test.js"
+ ]
+ }
+ }
+}
diff --git a/chrome/test/data/extensions/platform_apps/print_api/test.html b/chrome/test/data/extensions/platform_apps/print_api/test.html
new file mode 100644
index 0000000..de9facc
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/print_api/test.html
@@ -0,0 +1,10 @@
+ 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>
+11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>
+21<br>22<br>23<br>24<br>25<br>26<br>27<br>28<br>29<br>30<br>
+31<br>32<br>33<br>34<br>35<br>36<br>37<br>38<br>39<br>40<br>
+41<br>42<br>43<br>44<br>45<br>46<br>47<br>48<br>49<br>50<br>
+51<br>52<br>53<br>54<br>55<br>56<br>57<br>58<br>59<br>60<br>
+61<br>62<br>63<br>64<br>65<br>66<br>67<br>68<br>69<br>70<br>
+71<br>72<br>73<br>74<br>75<br>76<br>77<br>78<br>79<br>80<br>
+81<br>82<br>83<br>84<br>85<br>86<br>87<br>88<br>89<br>90<br>
+91<br>92<br>93<br>94<br>95<br>96<br>97<br>98<br>99<br>100<br>
diff --git a/chrome/test/data/extensions/platform_apps/print_api/test.js b/chrome/test/data/extensions/platform_apps/print_api/test.js
new file mode 100644
index 0000000..0a9e43b
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/print_api/test.js
@@ -0,0 +1,17 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+chrome.app.runtime.onLaunched.addListener(function() {
+ chrome.test.runTests([
+ function testWindowDotPrintCallWorks() {
+ chrome.app.window.create('test.html', {}, chrome.test.callbackPass(
+ function(appWindow) {
+ appWindow.contentWindow.onload = chrome.test.callbackPass(
+ function() {
+ appWindow.contentWindow.print();
+ });
+ }));
+ }
+ ]);
+});