Commit fb7bbce6 authored by Matt Menard's avatar Matt Menard Committed by Chromium LUCI CQ

Fix trailing 's' and print server printers reload

Fixes missing trailing 's' from WebUI message. Ensures print server
printers are always loaded after new print server is selected. Fixes
opposite flag for print server selector.

Bug: b:168650771
Change-Id: Ie2c7020d2f8752ab9bf00520a2b4ec3b6cddb776
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622352Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Matt Menard <mattme@google.com>
Cr-Commit-Position: refs/heads/master@{#843973}
parent 53b78f8c
...@@ -72,6 +72,7 @@ js_library("invitation_store") { ...@@ -72,6 +72,7 @@ js_library("invitation_store") {
if (is_chromeos_ash) { if (is_chromeos_ash) {
js_library("print_server_store") { js_library("print_server_store") {
deps = [ deps = [
":destination_store",
"..:native_layer_cros", "..:native_layer_cros",
"//ui/webui/resources/js/cr:event_target.m", "//ui/webui/resources/js/cr:event_target.m",
] ]
......
...@@ -596,6 +596,14 @@ export class DestinationStore extends EventTarget { ...@@ -596,6 +596,14 @@ export class DestinationStore extends EventTarget {
} }
}); });
} }
/**
* Reloads all local printers.
* @return {!Promise}
*/
reloadLocalPrinters() {
return this.nativeLayer_.getPrinters(PrinterType.LOCAL_PRINTER);
}
// </if> // </if>
/** /**
......
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js'; import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js';
import {DestinationStore} from './destination_store.js';
import {NativeLayerCros, NativeLayerCrosImpl, PrintServer, PrintServersConfig} from '../native_layer_cros.js'; import {NativeLayerCros, NativeLayerCrosImpl, PrintServer, PrintServersConfig} from '../native_layer_cros.js';
import {PrinterType} from './destination_match.js';
export class PrintServerStore extends EventTarget { export class PrintServerStore extends EventTarget {
/** /**
* A data store that stores print servers and dispatches events when the * A data store that stores print servers and dispatches events when the
...@@ -20,7 +23,7 @@ export class PrintServerStore extends EventTarget { ...@@ -20,7 +23,7 @@ export class PrintServerStore extends EventTarget {
* Used to fetch print servers. * Used to fetch print servers.
* @private {!NativeLayerCros} * @private {!NativeLayerCros}
*/ */
this.nativeLayer_ = NativeLayerCrosImpl.getInstance(); this.nativeLayerCros_ = NativeLayerCrosImpl.getInstance();
/** /**
* All available print servers mapped by name. * All available print servers mapped by name.
...@@ -34,6 +37,12 @@ export class PrintServerStore extends EventTarget { ...@@ -34,6 +37,12 @@ export class PrintServerStore extends EventTarget {
*/ */
this.isSingleServerFetchingMode_ = false; this.isSingleServerFetchingMode_ = false;
/**
* Used to reload local printers.
* @private {?DestinationStore}
*/
this.destinationStore_ = null;
addListenerCallback( addListenerCallback(
'print-servers-config-changed', 'print-servers-config-changed',
printServersConfig => printServersConfig =>
...@@ -49,7 +58,7 @@ export class PrintServerStore extends EventTarget { ...@@ -49,7 +58,7 @@ export class PrintServerStore extends EventTarget {
*/ */
choosePrintServers(printServerName) { choosePrintServers(printServerName) {
const printServers = this.printServersByName_.get(printServerName); const printServers = this.printServersByName_.get(printServerName);
this.nativeLayer_.choosePrintServers( this.nativeLayerCros_.choosePrintServers(
printServers ? printServers.map(printServer => printServer.id) : []); printServers ? printServers.map(printServer => printServer.id) : []);
} }
...@@ -58,7 +67,14 @@ export class PrintServerStore extends EventTarget { ...@@ -58,7 +67,14 @@ export class PrintServerStore extends EventTarget {
* @return {!Promise<!PrintServersConfig>} The print servers configuration. * @return {!Promise<!PrintServersConfig>} The print servers configuration.
*/ */
getPrintServersConfig() { getPrintServersConfig() {
return this.nativeLayer_.getPrintServersConfig(); return this.nativeLayerCros_.getPrintServersConfig();
}
/**
* @param {!DestinationStore} destinationStore The destination store.
*/
setDestinationStore(destinationStore) {
this.destinationStore_ = destinationStore;
} }
/** /**
...@@ -89,7 +105,10 @@ export class PrintServerStore extends EventTarget { ...@@ -89,7 +105,10 @@ export class PrintServerStore extends EventTarget {
* Called when print server printers loading status has changed. * Called when print server printers loading status has changed.
* @param {boolean} isLoading Whether server printers are loading * @param {boolean} isLoading Whether server printers are loading
*/ */
onServerPrintersLoading_(isLoading) { async onServerPrintersLoading_(isLoading) {
if (!isLoading && this.destinationStore_) {
await this.destinationStore_.reloadLocalPrinters();
}
this.dispatchEvent(new CustomEvent( this.dispatchEvent(new CustomEvent(
PrintServerStore.EventType.SERVER_PRINTERS_LOADING, PrintServerStore.EventType.SERVER_PRINTERS_LOADING,
{detail: isLoading})); {detail: isLoading}));
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<option value="">$i18n{addAccountTitle}</option> <option value="">$i18n{addAccountTitle}</option>
</select> </select>
</div> </div>
<div hidden$="[[printServerScalingFlagEnabled_]]" <div hidden$="[[!printServerScalingFlagEnabled_]]"
class="server-search-box-container"> class="server-search-box-container">
<!-- TODO(crbug.com/1013408): Uses deprecated iron-dropdown. --> <!-- TODO(crbug.com/1013408): Uses deprecated iron-dropdown. -->
<cr-searchable-drop-down class="server-search-box-input" <cr-searchable-drop-down class="server-search-box-input"
......
...@@ -184,6 +184,9 @@ Polymer({ ...@@ -184,6 +184,9 @@ Polymer({
config.printServers.map(printServer => printServer.name); config.printServers.map(printServer => printServer.name);
this.isSingleServerFetchingMode_ = config.isSingleServerFetchingMode; this.isSingleServerFetchingMode_ = config.isSingleServerFetchingMode;
}); });
if (this.destinationStore) {
this.printServerStore_.setDestinationStore(this.destinationStore);
}
}, },
/** /**
...@@ -211,6 +214,9 @@ Polymer({ ...@@ -211,6 +214,9 @@ Polymer({
destinationStore, DestinationStore.EventType.DESTINATION_SEARCH_DONE, destinationStore, DestinationStore.EventType.DESTINATION_SEARCH_DONE,
this.updateDestinations_.bind(this)); this.updateDestinations_.bind(this));
this.initialized_ = true; this.initialized_ = true;
if (this.printServerStore_) {
this.printServerStore_.setDestinationStore(this.destinationStore);
}
}, },
/** @private */ /** @private */
......
...@@ -132,9 +132,9 @@ void PrintPreviewHandlerChromeOS::RegisterMessages() { ...@@ -132,9 +132,9 @@ void PrintPreviewHandlerChromeOS::RegisterMessages() {
base::Unretained(this))); base::Unretained(this)));
if (base::FeatureList::IsEnabled(chromeos::features::kPrintServerScaling)) { if (base::FeatureList::IsEnabled(chromeos::features::kPrintServerScaling)) {
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"choosePrintServer", "choosePrintServers",
base::BindRepeating( base::BindRepeating(
&PrintPreviewHandlerChromeOS::HandleChoosePrintServer, &PrintPreviewHandlerChromeOS::HandleChoosePrintServers,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"getPrintServersConfig", "getPrintServersConfig",
...@@ -321,7 +321,7 @@ void PrintPreviewHandlerChromeOS::OnPrinterStatusUpdated( ...@@ -321,7 +321,7 @@ void PrintPreviewHandlerChromeOS::OnPrinterStatusUpdated(
ResolveJavascriptCallback(base::Value(callback_id), cups_printer_status); ResolveJavascriptCallback(base::Value(callback_id), cups_printer_status);
} }
void PrintPreviewHandlerChromeOS::HandleChoosePrintServer( void PrintPreviewHandlerChromeOS::HandleChoosePrintServers(
const base::ListValue* args) { const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize()); CHECK_EQ(1U, args->GetSize());
......
...@@ -105,7 +105,7 @@ class PrintPreviewHandlerChromeOS ...@@ -105,7 +105,7 @@ class PrintPreviewHandlerChromeOS
// Loads printers corresponding to the print server(s). First element of // Loads printers corresponding to the print server(s). First element of
// |args| is the print server IDs. // |args| is the print server IDs.
void HandleChoosePrintServer(const base::ListValue* args); void HandleChoosePrintServers(const base::ListValue* args);
// Gets the list of print servers and fetching mode. // Gets the list of print servers and fetching mode.
void HandleGetPrintServersConfig(const base::ListValue* args); void HandleGetPrintServersConfig(const base::ListValue* args);
......
...@@ -150,7 +150,7 @@ class PrintPreviewHandlerChromeOSTest : public testing::Test { ...@@ -150,7 +150,7 @@ class PrintPreviewHandlerChromeOSTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandlerChromeOSTest); DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandlerChromeOSTest);
}; };
TEST_F(PrintPreviewHandlerChromeOSTest, ChoosePrintServer) { TEST_F(PrintPreviewHandlerChromeOSTest, ChoosePrintServers) {
base::Value selected_args(base::Value::Type::LIST); base::Value selected_args(base::Value::Type::LIST);
base::Value selected_ids_js(base::Value::Type::LIST); base::Value selected_ids_js(base::Value::Type::LIST);
selected_ids_js.Append(kSelectedPrintServerId); selected_ids_js.Append(kSelectedPrintServerId);
...@@ -160,13 +160,13 @@ TEST_F(PrintPreviewHandlerChromeOSTest, ChoosePrintServer) { ...@@ -160,13 +160,13 @@ TEST_F(PrintPreviewHandlerChromeOSTest, ChoosePrintServer) {
base::Value none_selected_js(base::Value::Type::LIST); base::Value none_selected_js(base::Value::Type::LIST);
none_selected_args.Append(std::move(none_selected_js)); none_selected_args.Append(std::move(none_selected_js));
web_ui()->HandleReceivedMessage("choosePrintServer", web_ui()->HandleReceivedMessage("choosePrintServers",
&base::Value::AsListValue(selected_args)); &base::Value::AsListValue(selected_args));
EXPECT_THAT(print_servers_manager()->selected_print_server_ids(), EXPECT_THAT(print_servers_manager()->selected_print_server_ids(),
testing::ElementsAre(std::string(kSelectedPrintServerId))); testing::ElementsAre(std::string(kSelectedPrintServerId)));
web_ui()->HandleReceivedMessage( web_ui()->HandleReceivedMessage(
"choosePrintServer", &base::Value::AsListValue(none_selected_args)); "choosePrintServers", &base::Value::AsListValue(none_selected_args));
EXPECT_THAT(print_servers_manager()->selected_print_server_ids(), EXPECT_THAT(print_servers_manager()->selected_print_server_ids(),
testing::IsEmpty()); testing::IsEmpty());
......
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