0

Refactored code to move cloudprint specific code into print_preview_cloud.js.

Removed "Local" and "Cloud" labels from dropdown
The "More printers" label is now more clear and shares behavior with the cloud print printer option in Chrome.
The system print dialog link is replaced with a similar link referencing cloud print in chrome os.
Choosing cloud print from the printers dropdown now requires the user to hit print before opening the cloud print dialog.
Fixed broken tests.

BUG=88098, 97175, http://code.google.com/p/chromium-os/issues/detail?id=16082, http://code.google.com/p/chromium-os/issues/detail?id=20121, http://code.google.com/p/chromium-os/issues/detail?id=20119
TEST=Enable print preview in about:flags.  Printing should work with cloud print printers in much the same way as local printers in Chrome

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=103010

Review URL: http://codereview.chromium.org/7976017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103173 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
abodenha@google.com
2011-09-28 20:50:04 +00:00
parent fb6a4a95b8
commit f0be15bd73
10 changed files with 168 additions and 223 deletions

@ -6077,33 +6077,21 @@ Keep your key file in a safe place. You will need it to create new versions of y
desc="Option shown in printer drop-down list when the user isn't signed in to cloud print. Choosing it will display a sign in dialog.">
Sign in to access cloud printers...
</message>
<message name="IDS_PRINT_PREVIEW_CLOUD_PRINTERS"
desc="Option shown in printer drop-down list that serves as a heading above all cloud based printers.">
Cloud printers
</message>
<message name="IDS_PRINT_PREVIEW_LOCAL_PRINTERS"
desc="Option shown in printer drop-down list that serves as a heading above all locally installed printers.">
Local printers
</message>
<message name="IDS_PRINT_PREVIEW_MANAGE_CLOUD_PRINTERS"
desc="Option shown in printer drop-down list for managing cloud based printers.">
Manage cloud printers...
<message name="IDS_PRINT_PREVIEW_MORE_PRINTERS"
desc="Option shown in printer drop-down list that displays an interface for finding/using additional cloud based printers.">
Search for additional printers
</message>
<message name="IDS_PRINT_PREVIEW_MANAGE_PRINTERS"
desc="Option shown in printer drop-down list for managing printers.">
Manage printers...
</message>
<message name="IDS_PRINT_PREVIEW_MANAGE_LOCAL_PRINTERS"
desc="Option shown in printer drop-down list for managing local printers.">
Manage local printers...
</message>
<message name="IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT"
desc="Option shown in printer drop-down list to allow the user to print using cloud print.">
Print with Google Cloud Print...
desc="Option shown in printer drop-down list to allow the user to print using cloud print. Cloud print dialog will open when this option is selected and the user clicks print.">
Print with <ph name="CLOUD_PRINT_NAME">Google Cloud Print</ph>
</message>
<message name="IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT_WAIT"
desc="Message shown in the print preview page after choosing cloud print before the dialog displays">
Loading Google Cloud Print
Loading <ph name="CLOUD_PRINT_NAME">Google Cloud Print</ph>
</message>
<message name="IDS_PRINT_PREVIEW_SUMMARY_FORMAT_LONG" desc="Print summary, explaining to the user how many pages will be printed.">
Total: <ph name="NUMBER_OF_SHEETS">$1<ex>10</ex></ph> <ph name="SHEETS_LABEL">$2<ex>sheets of paper</ex></ph> (<ph name="NUMBER_OF_PAGES">$3<ex>4</ex></ph> <ph name="PAGE_OR_PAGES_LABEL">$4<ex>Pages</ex></ph>)
@ -6126,6 +6114,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION" desc="Option allowing the user to access advanced printer settings using the native print system dialog instead of printing through the print preview mechanism. Shortcut key is not translated">
Print using system dialog... <ph name="SHORTCUT_KEY">$1<ex>(Shift+Ctrl+P)</ex></ph>
</message>
<message name="IDS_PRINT_PREVIEW_CLOUD_DIALOG_OPTION" desc="Option allowing the user to access advanced printer settings using the cloud print dialog instead of printing through the print preview mechanism.">
Print using <ph name="CLOUD_PRINT_NAME">Google Cloud Print</ph> dialog... <ph name="SHORTCUT_KEY">$1<ex>(Shift+Ctrl+P)</ex></ph>
</message>
<message name="IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION" desc="Instruction shown when the user enters an invalid page range.">
Invalid page range, use <ph name="EXAMPLE_PAGE_RANGE">$1<ex>e.g. 1-5, 8, 11-13</ex></ph>
</message>

@ -46,8 +46,14 @@
<include src="header_footer_settings.html"></include>
<hr>
<div id="system-dialog-div">
<button id="system-dialog-link" class="link-button"
i18n-content="systemDialogOption"></button>
<if expr="pp_ifdef('chromeos')">
<button id="system-dialog-link" class="link-button"
i18n-content="cloudPrintDialogOption"></button>
</if>
<if expr="not pp_ifdef('chromeos')">
<button id="system-dialog-link" class="link-button"
i18n-content="systemDialogOption"></button>
</if>
<!-- TODO(dpapad): Investigate whey hidden attribute does not work. -->
<div id="system-dialog-throbber" class="throbber hidden"></div>
</div>

@ -85,10 +85,6 @@ var currentPreviewUid = '';
// True if we need to generate draft preview data.
var generateDraftData = true;
// TODO(abodenha@chromium.org) A lot of cloud print specific logic has
// made its way into this file. Refactor to create a cleaner boundary
// between print preview and GCP code. Reference bug 88098 when fixing.
// A dictionary of cloud printers that have been added to the printer
// dropdown.
var addedCloudPrinters = {};
@ -223,12 +219,8 @@ function updateControlsWithSelectedPrinterCapabilities() {
var skip_refresh = false;
var selectedValue = printerList.options[selectedIndex].value;
if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) {
updateWithCloudPrinterCapabilities();
skip_refresh = true;
} else if (selectedValue == PRINT_WITH_CLOUD_PRINT) {
// If a preview is pending this will just disable controls.
// Once the preview completes we'll try again.
printWithCloudPrintDialog();
cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
doUpdateCloudPrinterCapabilities);
skip_refresh = true;
} else if (selectedValue == SIGN_IN ||
selectedValue == MANAGE_CLOUD_PRINTERS ||
@ -236,7 +228,8 @@ function updateControlsWithSelectedPrinterCapabilities() {
printerList.selectedIndex = lastSelectedPrinterIndex;
chrome.send(selectedValue);
skip_refresh = true;
} else if (selectedValue == PRINT_TO_PDF) {
} else if (selectedValue == PRINT_TO_PDF ||
selectedValue == PRINT_WITH_CLOUD_PRINT) {
updateWithPrinterCapabilities({
'disableColorOption': true,
'setColorAsDefault': true,
@ -257,17 +250,6 @@ function updateControlsWithSelectedPrinterCapabilities() {
}
}
/**
* Updates the printer capabilities for the currently selected
* cloud print printer.
*/
function updateWithCloudPrinterCapabilities() {
var printerList = $('printer-list');
var selectedIndex = printerList.selectedIndex;
cloudprint.updatePrinterCaps(printerList.options[selectedIndex],
doUpdateCloudPrinterCapabilities);
}
/**
* Helper function to do the actual work of updating cloud printer
* capabilities.
@ -329,9 +311,11 @@ function finishedCloudPrinting() {
* @return {boolean} true if settings are valid, false if not.
*/
function areSettingsValid() {
var selectedPrinter = getSelectedPrinterName();
return pageSettings.isPageSelectionValid() &&
(copiesSettings.isValid() ||
getSelectedPrinterName() == PRINT_TO_PDF);
selectedPrinter == PRINT_TO_PDF ||
selectedPrinter == PRINT_WITH_CLOUD_PRINT);
}
/**
@ -341,7 +325,8 @@ function areSettingsValid() {
*/
function getSettings() {
var deviceName = getSelectedPrinterName();
var printToPDF = (deviceName == PRINT_TO_PDF);
var printToPDF = deviceName == PRINT_TO_PDF;
var printWithCloudPrint = deviceName == PRINT_WITH_CLOUD_PRINT;
var settings =
{'deviceName': deviceName,
@ -352,6 +337,7 @@ function getSettings() {
'landscape': layoutSettings.isLandscape(),
'color': colorSettings.colorMode,
'printToPDF': printToPDF,
'printWithCloudPrint': printWithCloudPrint,
'isFirstRequest' : false,
'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(),
'defaultMarginsSelected': marginSettings.isDefaultMarginsSelected(),
@ -435,11 +421,15 @@ function getSelectedPrinterName() {
*/
function requestToPrintDocument() {
hasPendingPrintDocumentRequest = !isPrintReadyMetafileReady;
var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF;
var selectedPrinterName = getSelectedPrinterName();
var printToPDF = selectedPrinterName == PRINT_TO_PDF;
var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT;
if (hasPendingPrintDocumentRequest) {
if (printToPDF) {
sendPrintDocumentRequest();
} else if (printWithCloudPrint) {
showCustomMessage(localStrings.getString('printWithCloudPrintWait'));
disableInputElementsInSidebar();
} else {
isTabHidden = true;
chrome.send('hidePreview');
@ -552,7 +542,7 @@ function setDefaultPrinter(printer_name, cloudPrintData) {
if (cloudPrintData) {
cloudprint.setDefaultPrinter(printer_name,
cloudPrintData,
addCloudPrinters,
addDestinationListOptionAtPosition,
doUpdateCloudPrinterCapabilities);
} else {
$('printer-list')[0].value = defaultOrLastUsedPrinterName;
@ -598,14 +588,14 @@ function setPrinters(printers) {
}
// Add options to manage printers.
if (!cr.isChromeOS) {
addDestinationListOption(localStrings.getString('manageLocalPrinters'),
addDestinationListOption(localStrings.getString('managePrinters'),
MANAGE_LOCAL_PRINTERS, false, false, false);
} else if (useCloudPrint) {
// Fetch recent printers.
cloudprint.fetchPrinters(addCloudPrinters, false);
cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false);
// Fetch the full printer list.
cloudprint.fetchPrinters(addCloudPrinters, true);
addDestinationListOption(localStrings.getString('manageCloudPrinters'),
cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true);
addDestinationListOption(localStrings.getString('managePrinters'),
MANAGE_CLOUD_PRINTERS, false, false, false);
}
@ -683,108 +673,6 @@ function addDestinationListOptionAtPosition(position,
printerList.add(option, before);
return option;
}
/**
* Test if a particular cloud printer has already been added to the
* printer dropdown.
* @param {string} id A unique value to track this printer.
* @return {boolean} True if this id has previously been passed to
* trackCloudPrinterAdded.
*/
function cloudPrinterAlreadyAdded(id) {
return (addedCloudPrinters[id]);
}
/**
* Record that a cloud printer will added to the printer dropdown.
* @param {string} id A unique value to track this printer.
* @return {boolean} False if adding this printer would exceed
* |maxCloudPrinters|.
*/
function trackCloudPrinterAdded(id) {
if (Object.keys(addedCloudPrinters).length < maxCloudPrinters) {
addedCloudPrinters[id] = true;
return true;
} else {
return false;
}
}
/**
* Add cloud printers to the list drop down.
* Called from the cloudprint object on receipt of printer information from the
* cloud print server.
* @param {Array} printers Array of printer info objects.
* @return {Object} The currently selected printer.
*/
function addCloudPrinters(printers) {
var isFirstPass = false;
var printerList = $('printer-list');
if (firstCloudPrintOptionPos == lastCloudPrintOptionPos) {
isFirstPass = true;
// Remove empty entry added by setDefaultPrinter.
if (printerList[0] && printerList[0].textContent == '')
printerList.remove(0);
var option = addDestinationListOptionAtPosition(
lastCloudPrintOptionPos++,
localStrings.getString('cloudPrinters'),
'Label',
false,
true,
false);
cloudprint.setCloudPrint(option, null, null);
}
if (printers != null) {
for (var i = 0; i < printers.length; i++) {
if (!cloudPrinterAlreadyAdded(printers[i]['id'])) {
if (!trackCloudPrinterAdded(printers[i]['id'])) {
break;
}
var option = addDestinationListOptionAtPosition(
lastCloudPrintOptionPos++,
printers[i]['name'],
printers[i]['id'],
printers[i]['name'] == defaultOrLastUsedPrinterName,
false,
false);
cloudprint.setCloudPrint(option,
printers[i]['name'],
printers[i]['id']);
}
}
} else {
if (!cloudPrinterAlreadyAdded(SIGN_IN)) {
addDestinationListOptionAtPosition(lastCloudPrintOptionPos++,
localStrings.getString('signIn'),
SIGN_IN,
false,
false,
false);
trackCloudPrinterAdded(SIGN_IN);
}
}
if (isFirstPass) {
addDestinationListOptionAtPosition(lastCloudPrintOptionPos,
'',
'',
false,
true,
true);
addDestinationListOptionAtPosition(lastCloudPrintOptionPos + 1,
localStrings.getString('localPrinters'),
'',
false,
true,
false);
}
var selectedPrinter = printerList.selectedIndex;
if (selectedPrinter < 0)
return null;
return printerList.options[selectedPrinter];
}
/**
* Sets the color mode for the PDF plugin.
* Called from PrintPreviewHandler::ProcessColorSetting().
@ -909,9 +797,9 @@ function onDidGetDefaultPageLayout(pageLayout) {
*/
function checkAndHideOverlayLayerIfValid() {
var selectedPrinter = getSelectedPrinterName();
var printToPDF = selectedPrinter == PRINT_TO_PDF;
var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT;
if ((printToPDF || printWithCloudPrint || !previewModifiable) &&
var printToDialog = selectedPrinter == PRINT_TO_PDF ||
selectedPrinter == PRINT_WITH_CLOUD_PRINT;
if ((printToDialog || !previewModifiable) &&
!isPrintReadyMetafileReady && hasPendingPrintDocumentRequest) {
return;
}
@ -1016,19 +904,14 @@ function sendPrintDocumentRequestIfNeeded() {
// printing. If the preview source is modifiable, we need to wait till all
// the requested pages are loaded in the plugin for printing.
var selectedPrinter = getSelectedPrinterName();
var printToPDF = selectedPrinter == PRINT_TO_PDF;
var printWithCloudPrint = selectedPrinter == PRINT_WITH_CLOUD_PRINT;
if (((printToPDF || !previewModifiable || printWithCloudPrint) &&
!isPrintReadyMetafileReady) ||
var printToDialog = selectedPrinter == PRINT_TO_PDF ||
selectedPrinter == PRINT_WITH_CLOUD_PRINT;
if (((printToDialog || !previewModifiable) && !isPrintReadyMetafileReady) ||
(previewModifiable && hasPendingPreviewRequest)) {
return;
}
hasPendingPrintDocumentRequest = false;
if (printWithCloudPrint) {
chrome.send('printWithCloudPrint');
return;
}
if (!areSettingsValid()) {
if (isTabHidden)
@ -1141,21 +1024,6 @@ function setInitiatorTabTitle(initiatorTabTitle) {
'printPreviewTitleFormat', initiatorTabTitle);
}
/**
* Attempt to hide the preview tab and display the Cloud Print
* dialog instead. Just disables controls if we're waiting on a new preview
* to be generated.
*/
function printWithCloudPrintDialog() {
if (isPrintReadyMetafileReady) {
chrome.send('printWithCloudPrint');
} else {
showCustomMessage(localStrings.getString('printWithCloudPrintWait'));
disableInputElementsInSidebar();
hasPendingPrintDocumentRequest = true;
}
}
/// Pull in all other scripts in a single shot.
<include src="print_preview_animations.js"/>
<include src="print_preview_cloud.js"/>

@ -119,13 +119,11 @@ cr.define('cloudprint', function() {
var searchResult = JSON.parse(xhr.responseText);
if (searchResult['success']) {
var printerList = searchResult['printers'];
callback.call(this, printerList);
} else {
callback.call(this, null);
addCloudPrinters(printerList, callback);
return;
}
} else {
callback.call(this, null);
}
addCloudPrinters(null, callback);
}
/**
@ -306,7 +304,8 @@ cr.define('cloudprint', function() {
cloud_print_data,
add_callback,
update_caps_callback) {
var printer = add_callback([JSON.parse(cloud_print_data)]);
var printer = addCloudPrinters([JSON.parse(cloud_print_data)],
add_callback);
if (printer)
update_caps_callback(printer);
}
@ -350,7 +349,87 @@ cr.define('cloudprint', function() {
printer.cloudPrintOptions.id = id;
}
/**
* Test if a particular cloud printer has already been added to the
* printer dropdown.
* @param {string} id A unique value to track this printer.
* @return {boolean} True if |id| has previously been passed to
* trackCloudPrinterAdded.
*/
function cloudPrinterAlreadyAdded(id) {
return addedCloudPrinters[id];
}
/**
* Test if a particular printer has already been added to the printers
* dropdown. Records it if not.
* @param {string} id A unique value to track this printer.
* @return {boolean} False if adding this printer would exceed
* |maxCloudPrinters|.
*/
function trackCloudPrinterAdded(id) {
if (Object.keys(addedCloudPrinters).length < maxCloudPrinters) {
addedCloudPrinters[id] = true;
return true;
} else {
return false;
}
}
/**
* Add cloud printers to the list drop down.
* Called from the cloudprint object on receipt of printer information from
* the cloud print server.
* @param {Array} printers Array of printer info objects.
* @return {Object} The currently selected printer.
*/
function addCloudPrinters(printers, addDestinationListOptionAtPosition) {
var isFirstPass = false;
var printerList = $('printer-list');
if (firstCloudPrintOptionPos == lastCloudPrintOptionPos) {
isFirstPass = true;
// Remove empty entry added by setDefaultPrinter.
if (printerList[0] && printerList[0].textContent == '')
printerList.remove(0);
}
if (printers != null) {
for (var i = 0; i < printers.length; i++) {
if (!cloudPrinterAlreadyAdded(printers[i]['id'])) {
if (!trackCloudPrinterAdded(printers[i]['id'])) {
break;
}
var option = addDestinationListOptionAtPosition(
lastCloudPrintOptionPos++,
printers[i]['name'],
printers[i]['id'],
printers[i]['name'] == defaultOrLastUsedPrinterName,
false,
false);
cloudprint.setCloudPrint(option,
printers[i]['name'],
printers[i]['id']);
}
}
} else {
if (!cloudPrinterAlreadyAdded(SIGN_IN)) {
addDestinationListOptionAtPosition(lastCloudPrintOptionPos++,
localStrings.getString('signIn'),
SIGN_IN,
false,
false,
false);
trackCloudPrinterAdded(SIGN_IN);
}
}
var selectedPrinter = printerList.selectedIndex;
if (selectedPrinter < 0)
return null;
return printerList.options[selectedPrinter];
}
return {
addCloudPrinters: addCloudPrinters,
colorIsDefault: colorIsDefault,
fetchPrinters: fetchPrinters,
getBaseURL: getBaseURL,

@ -93,25 +93,26 @@ PrintPreviewDataSource::PrintPreviewDataSource()
AddLocalizedString("printPreviewPageLabelPlural",
IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL);
const string16 shortcut_text(UTF8ToUTF16(kAdvancedPrintShortcut));
#if defined(OS_CHROMEOS)
AddString("cloudPrintDialogOption", l10n_util::GetStringFUTF16(
IDS_PRINT_PREVIEW_CLOUD_DIALOG_OPTION,
shortcut_text));
AddLocalizedString("printWithCloudPrint",
IDS_PRINT_PREVIEW_MORE_PRINTERS);
#else
AddString("systemDialogOption", l10n_util::GetStringFUTF16(
IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION,
shortcut_text));
AddLocalizedString("printWithCloudPrint",
IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT);
#endif
AddLocalizedString("pageRangeInstruction",
IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION);
AddLocalizedString("copiesInstruction", IDS_PRINT_PREVIEW_COPIES_INSTRUCTION);
AddLocalizedString("signIn", IDS_PRINT_PREVIEW_SIGN_IN);
AddLocalizedString("cloudPrinters", IDS_PRINT_PREVIEW_CLOUD_PRINTERS);
AddLocalizedString("localPrinters", IDS_PRINT_PREVIEW_LOCAL_PRINTERS);
AddLocalizedString("manageCloudPrinters",
IDS_PRINT_PREVIEW_MANAGE_CLOUD_PRINTERS);
AddLocalizedString("manageLocalPrinters",
IDS_PRINT_PREVIEW_MANAGE_LOCAL_PRINTERS);
AddLocalizedString("managePrinters", IDS_PRINT_PREVIEW_MANAGE_PRINTERS);
AddLocalizedString("printWithCloudPrintWait",
IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT_WAIT);
AddLocalizedString("printWithCloudPrint",
IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT);
AddLocalizedString("incrementTitle", IDS_PRINT_PREVIEW_INCREMENT_TITLE);
AddLocalizedString("decrementTitle", IDS_PRINT_PREVIEW_DECREMENT_TITLE);
AddLocalizedString("printPagesLabel", IDS_PRINT_PREVIEW_PRINT_PAGES_LABEL);

@ -565,8 +565,6 @@ void PrintPreviewHandler::RegisterMessages() {
NewCallback(this, &PrintPreviewHandler::HandleShowSystemDialog));
web_ui_->RegisterMessageCallback("signIn",
NewCallback(this, &PrintPreviewHandler::HandleSignin));
web_ui_->RegisterMessageCallback("printWithCloudPrint",
NewCallback(this, &PrintPreviewHandler::HandlePrintWithCloudPrint));
web_ui_->RegisterMessageCallback("manageCloudPrinters",
NewCallback(this, &PrintPreviewHandler::HandleManageCloudPrint));
web_ui_->RegisterMessageCallback("manageLocalPrinters",
@ -715,13 +713,17 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false);
bool print_to_cloud = settings->HasKey(printing::kSettingCloudPrintId);
if (print_to_cloud) {
bool is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId);
bool is_cloud_dialog = false;
settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog);
if (is_cloud_printer) {
std::string print_ticket;
args->GetString(1, &print_ticket);
SendCloudPrintJob(*settings, print_ticket);
} else if (print_to_pdf) {
HandlePrintToPdf(*settings);
} else if (is_cloud_dialog) {
HandlePrintWithCloudPrint();
} else {
ReportPrintSettingsStats(*settings);
ReportUserActionHistogram(PRINT_TO_PRINTER);
@ -830,7 +832,7 @@ void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) {
cloud_print_signin_dialog::CreateCloudPrintSigninDialog(preview_tab());
}
void PrintPreviewHandler::HandlePrintWithCloudPrint(const ListValue* /*args*/) {
void PrintPreviewHandler::HandlePrintWithCloudPrint() {
// Record the number of times the user asks to print via cloud print
// instead of the print preview dialog.
ReportStats();

@ -142,8 +142,8 @@ class PrintPreviewHandler : public WebUIMessageHandler,
// |args| is unused.
void HandleManagePrinters(const base::ListValue* args);
// Asks the browser to show the cloud print dialog. |args| is unused.
void HandlePrintWithCloudPrint(const base::ListValue* args);
// Asks the browser to show the cloud print dialog.
void HandlePrintWithCloudPrint();
// Asks the browser to close the preview tab. |args| is unused.
void HandleClosePreviewTab(const base::ListValue* args);

@ -235,48 +235,42 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
// Test that the printer list is structured correctly after calling
// addCloudPrinters with an empty list.
TEST_F('PrintPreviewWebUITest', 'FLAKY_TestPrinterListCloudEmpty', function() {
addCloudPrinters([]);
TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
cloudprint.addCloudPrinters([], addDestinationListOptionAtPosition);
var printerList = $('printer-list');
assertNotEquals(null, printerList);
expectEquals(localStrings.getString('cloudPrinters'),
printerList.options[0].text);
expectEquals(localStrings.getString('addCloudPrinter'),
printerList.options[1].text);
});
// Test that the printer list is structured correctly after calling
// addCloudPrinters with a null list.
TEST_F('PrintPreviewWebUITest', 'FLAKY_TestPrinterListCloudNull', function() {
addCloudPrinters(null);
TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudNull', function() {
cloudprint.addCloudPrinters(null, addDestinationListOptionAtPosition);
var printerList = $('printer-list');
assertNotEquals(null, printerList);
expectEquals(localStrings.getString('cloudPrinters'),
printerList.options[0].text);
expectEquals(localStrings.getString('signIn'),
printerList.options[1].text);
printerList.options[0].text);
});
// Test that the printer list is structured correctly after attempting to add
// individual cloud printers until no more can be added.
TEST_F('PrintPreviewWebUITest', 'FLAKY_TestPrinterListCloud', function() {
TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloud', function() {
var printerList = $('printer-list');
assertNotEquals(null, printerList);
var printer = new Object;
printer['name'] = 'FooCloud';
for (var i = 0; i < maxCloudPrinters; i++) {
printer['id'] = String(i);
addCloudPrinters([printer]);
expectEquals(localStrings.getString('cloudPrinters'),
printerList.options[0].text);
expectEquals('FooCloud', printerList.options[i + 1].text);
expectEquals(String(i), printerList.options[i + 1].value);
cloudprint.addCloudPrinters([printer], addDestinationListOptionAtPosition);
expectEquals('FooCloud', printerList.options[i].text);
expectEquals(String(i), printerList.options[i].value);
}
cloudprint.addCloudPrinters([printer], addDestinationListOptionAtPosition);
expectNotEquals('FooCloud', printerList.options[i].text);
expectNotEquals(String(i), printerList.options[i].value);
for (var i = 0; i < maxCloudPrinters; i++) {
expectEquals('FooCloud', printerList.options[i].text);
expectEquals(String(i), printerList.options[i].value);
}
printer['id'] = maxCloudPrinters + 1;
addCloudPrinters([printer]);
expectEquals('', printerList.options[maxCloudPrinters + 1].text);
expectEquals(localStrings.getString('morePrinters'),
printerList.options[maxCloudPrinters + 2].text);
});
/**

@ -18,6 +18,9 @@ const char kPreviewUIAddr[] = "previewUIAddr";
// Print using cloud print: true if selected, false if not.
const char kSettingCloudPrintId[] = "cloudPrintID";
// Print using cloud print dialog: true if selected, false if not.
const char kSettingCloudPrintDialog[] = "printWithCloudPrint";
// Print job setting 'collate'.
const char kSettingCollate[] = "collate";

@ -13,6 +13,7 @@ PRINTING_EXPORT extern const char kIsFirstRequest[];
PRINTING_EXPORT extern const char kPreviewRequestID[];
PRINTING_EXPORT extern const char kPreviewUIAddr[];
PRINTING_EXPORT extern const char kSettingCloudPrintId[];
PRINTING_EXPORT extern const char kSettingCloudPrintDialog[];
PRINTING_EXPORT extern const char kSettingCollate[];
PRINTING_EXPORT extern const char kSettingColor[];
PRINTING_EXPORT extern const char kSettingContentHeight[];