Cleaned up the print preview API used by app printing browser tests

Added an anonymous namespace to make a couple of methods of this testing
API private.

BUG=none

Review URL: https://chromiumcodereview.appspot.com/24158002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223363 0039d316-1c4b-4281-b951-d872f2087c98
parent e9fa65c6
...@@ -338,6 +338,29 @@ content::WebUIDataSource* CreatePrintPreviewUISource() { ...@@ -338,6 +338,29 @@ content::WebUIDataSource* CreatePrintPreviewUISource() {
return source; return source;
} }
int g_auto_cancel_count_for_testing_ = -1; // Disabled if count < 0.
void EnableAutoCancelAndResetCountForTesting() {
g_auto_cancel_count_for_testing_ = 0;
}
void DisableAutoCancelForTesting() {
g_auto_cancel_count_for_testing_ = -1;
}
bool IsAutoCancelEnabledForTesting() {
return (g_auto_cancel_count_for_testing_ >= 0);
}
void IncrementAutoCancelCountForTesting() {
if (g_auto_cancel_count_for_testing_ >= 0)
++g_auto_cancel_count_for_testing_;
}
int GetAutoCancelCountForTesting() {
return std::max(g_auto_cancel_count_for_testing_, -1);
}
} // namespace } // namespace
PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui)
...@@ -520,8 +543,8 @@ void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, ...@@ -520,8 +543,8 @@ void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
} }
base::FundamentalValue ui_identifier(id_); base::FundamentalValue ui_identifier(id_);
base::FundamentalValue ui_preview_request_id(preview_request_id); base::FundamentalValue ui_preview_request_id(preview_request_id);
if (ScopedAutoCancelForTesting::IsEnabledForTesting()) { if (IsAutoCancelEnabledForTesting()) {
ScopedAutoCancelForTesting::IncrementCountForTesting(); IncrementAutoCancelCountForTesting();
OnClosePrintPreviewDialog(); OnClosePrintPreviewDialog();
} else { } else {
web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier, web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier,
...@@ -588,25 +611,14 @@ void PrintPreviewUI::OnPrintPreviewScalingDisabled() { ...@@ -588,25 +611,14 @@ void PrintPreviewUI::OnPrintPreviewScalingDisabled() {
web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF"); web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF");
} }
static int g_auto_cancel_count_for_testing_ = -1; // Disabled if count < 0.
PrintPreviewUI::ScopedAutoCancelForTesting::ScopedAutoCancelForTesting() { PrintPreviewUI::ScopedAutoCancelForTesting::ScopedAutoCancelForTesting() {
g_auto_cancel_count_for_testing_ = 0; EnableAutoCancelAndResetCountForTesting();
} }
PrintPreviewUI::ScopedAutoCancelForTesting::~ScopedAutoCancelForTesting() { PrintPreviewUI::ScopedAutoCancelForTesting::~ScopedAutoCancelForTesting() {
g_auto_cancel_count_for_testing_ = -1; DisableAutoCancelForTesting();
}
bool PrintPreviewUI::ScopedAutoCancelForTesting::IsEnabledForTesting() {
return (g_auto_cancel_count_for_testing_ >= 0);
}
void PrintPreviewUI::ScopedAutoCancelForTesting::IncrementCountForTesting() {
if (g_auto_cancel_count_for_testing_ >= 0)
++g_auto_cancel_count_for_testing_;
} }
int PrintPreviewUI::ScopedAutoCancelForTesting::GetCountForTesting() { int PrintPreviewUI::ScopedAutoCancelForTesting::GetCountForTesting() {
return std::max(g_auto_cancel_count_for_testing_, -1); return GetAutoCancelCountForTesting();
} }
...@@ -154,8 +154,6 @@ class PrintPreviewUI : public ConstrainedWebDialogUI { ...@@ -154,8 +154,6 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
public: public:
ScopedAutoCancelForTesting(); ScopedAutoCancelForTesting();
~ScopedAutoCancelForTesting(); ~ScopedAutoCancelForTesting();
static bool IsEnabledForTesting();
static void IncrementCountForTesting();
int GetCountForTesting(); int GetCountForTesting();
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment