Index: chrome/test/data/webui/print_preview_destination_search_test.js |
diff --git a/chrome/test/data/webui/print_preview_destination_search_test.js b/chrome/test/data/webui/print_preview_destination_search_test.js |
index b2f38db8730782a4749227cea1ce0c2898588900..33caa4e6e88fbe0955d32bd176dcb634ac59e130 100644 |
--- a/chrome/test/data/webui/print_preview_destination_search_test.js |
+++ b/chrome/test/data/webui/print_preview_destination_search_test.js |
@@ -24,7 +24,10 @@ PrintPreviewDestinationSearchTest.prototype = { |
runAccessibilityChecks: false, |
/** @override */ |
- extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
+ extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ |
+ ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js', |
+ ]), |
+ |
}; |
TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
@@ -102,14 +105,13 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
var resolver = new PromiseResolver(); |
if (cr.isChromeOS) { |
- nativeLayerMock.expects(once()).setupPrinter(destId). |
+ nativeLayerMock.whenCalled('setupPrinter'). |
will(returnValue(resolver.promise)); |
return resolver; |
} |
- nativeLayerMock.expects(once()).startGetLocalDestinationCapabilities( |
- destId); |
+ nativeLayerMock.setDestinationToWatch(destId); |
resolver.promise.then( |
function(result) { |
// Simulate the native layer dispatching capabilities. |
@@ -117,12 +119,14 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
capsSetEvent.settingsInfo = result; |
destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent); |
+ expectTrue(nativeLayerMock.didGetCapabilitiesOnce(destId)); |
}.bind(this), |
function() { |
var failEvent = new Event( |
print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL); |
failEvent.destinationId = destId; |
destinationStore_.onGetCapabilitiesFail_(failEvent); |
+ expectTrue(nativeLayerMock.didGetCapabilitiesOnce(destId)); |
}.bind(this)); |
return resolver; |
@@ -159,16 +163,52 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
resolver.resolve(response); |
} |
+ /** |
+ * Test version of the native layer. |
+ * @constructor |
+ * @extends {settings.TestBrowserProxy} |
+ */ |
+ function NativeLayerStub() { |
+ settings.TestBrowserProxy.call(this, [ 'getInitialSettings' ]); |
+ this.destinationToWatch_ = ''; |
+ this.eventTarget_ = mock(cr.EventTarget); |
+ this.getLocalDestinationCapabilitiesCallCount_ = 0; |
+ } |
+ |
+ NativeLayerStub.prototype = { |
+ __proto__: settings.TestBrowserProxy.prototype, |
+ didGetCapabilitiesOnce: function(destinationId) { |
+ return (destinationId == this.destinationToWatch_ && |
+ this.getLocalDestinationCapabilitiesCallCount_ == 1); |
+ }, |
+ getEventTarget: function() { return this.eventTarget_; }, |
+ setDestinationToWatch: function(destinationId) { |
+ this.destinationToWatch_ = destinationId; |
+ this.getLocalDestinationCapabilitiesCallCount_ = 0; |
+ }, |
+ setupPrinter: function() { |
+ this.methodCalled('setupPrinter'); |
+ }, |
+ startGetLocalDestinationCapabilities: function(destinationId) { |
+ if (destinationId == this.destinationToWatch_) |
+ this.getLocalDestinationCapabilitiesCallCount_++; |
+ }, |
+ startHideDialog: function () {}, |
+ }; |
+ NativeLayerStub.EventType = print_preview.NativeLayer.EventType; |
+ |
setup(function() { |
Mock4JS.clearMocksToVerify(); |
- |
- nativeLayer_ = mock(print_preview.NativeLayer); |
- nativeLayer_.expects(atLeastOnce()) |
+ nativeLayer_ = new NativeLayerStub(); |
+ var nativeLayerEventTarget = nativeLayer_.getEventTarget(); |
+ nativeLayerEventTarget.expects(atLeastOnce()) |
.addEventListener(ANYTHING, ANYTHING, ANYTHING); |
invitationStore_ = new print_preview.InvitationStore(); |
+ var nativeLayerProxy = nativeLayer_; |
+ nativeLayerProxy.eventTarget_ = nativeLayerEventTarget.proxy(); |
destinationStore_ = new print_preview.DestinationStore( |
- nativeLayer_.proxy(), new print_preview.UserInfo(), |
+ nativeLayerProxy, new print_preview.UserInfo(), |
new print_preview.AppState()); |
userInfo_ = new print_preview.UserInfo(); |