blob: ee17e94951fd49bceaef03650cdf9235e8cb4052 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2012 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.
#include "base/command_line.h"
#include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/printing/print_view_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents_observer.h"
#include "googleurl/src/gurl.h"
using content::WebContents;
class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest {
public:
PrintPreviewDialogControllerBrowserTest() {}
virtual ~PrintPreviewDialogControllerBrowserTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
#if !defined(GOOGLE_CHROME_BUILD)
command_line->AppendSwitch(switches::kEnablePrintPreview);
#endif
}
};
class PrintPreviewDialogDestroyedObserver
: public content::WebContentsObserver {
public:
explicit PrintPreviewDialogDestroyedObserver(WebContents* dialog)
: content::WebContentsObserver(dialog),
dialog_destroyed_(false) {
}
virtual ~PrintPreviewDialogDestroyedObserver() {}
bool dialog_destroyed() { return dialog_destroyed_; }
private:
virtual void WebContentsDestroyed(WebContents* contents) OVERRIDE {
dialog_destroyed_ = true;
}
bool dialog_destroyed_;
};
// Test to verify that when a initiator tab navigates, we can create a new
// preview dialog for the new tab contents.
IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
NavigateFromInitiatorTab) {
// Create a reference to initiator tab contents.
WebContents* initiator_tab =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(initiator_tab);
printing::PrintPreviewDialogController* dialog_controller =
printing::PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);
// Get the preview dialog for the initiator tab.
printing::PrintViewManager* print_view_manager =
printing::PrintViewManager::FromWebContents(initiator_tab);
print_view_manager->PrintPreviewNow(false);
WebContents* preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
// Check a new print preview dialog got created.
ASSERT_TRUE(preview_dialog);
ASSERT_NE(initiator_tab, preview_dialog);
// Navigate in the initiator tab. Make sure navigating destroys the print
// preview dialog.
PrintPreviewDialogDestroyedObserver observer(preview_dialog);
GURL url(chrome::kChromeUINewTabURL);
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_TRUE(observer.dialog_destroyed());
// Get the print preview dialog for the initiator tab.
print_view_manager->PrintPreviewNow(false);
WebContents* new_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
// Check a new preview dialog got created.
EXPECT_TRUE(new_preview_dialog);
}
// Test to verify that after reloading the initiator tab, it creates a new
// print preview dialog.
IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
ReloadInitiatorTab) {
// Create a reference to initiator tab contents.
WebContents* initiator_tab =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(initiator_tab);
printing::PrintPreviewDialogController* dialog_controller =
printing::PrintPreviewDialogController::GetInstance();
ASSERT_TRUE(dialog_controller);
// Create a preview dialog for the initiator tab.
printing::PrintViewManager* print_view_manager =
printing::PrintViewManager::FromWebContents(initiator_tab);
print_view_manager->PrintPreviewNow(false);
WebContents* preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
// Check a new print preview dialog got created.
ASSERT_TRUE(preview_dialog);
ASSERT_NE(initiator_tab, preview_dialog);
// Reload the initiator tab. Make sure reloading destroys the print preview
// dialog.
PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_dialog);
content::WindowedNotificationObserver notification_observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::Reload(browser(), CURRENT_TAB);
notification_observer.Wait();
ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed());
// Create a preview dialog for the initiator tab.
print_view_manager->PrintPreviewNow(false);
WebContents* new_preview_dialog =
dialog_controller->GetOrCreatePreviewDialog(initiator_tab);
EXPECT_TRUE(new_preview_dialog);
}
|