Merge "ui/navigator: allow tests, fix navigate return, add tests"

This commit is contained in:
mpl 2015-06-04 22:17:08 +00:00 committed by Gerrit Code Review
commit 630052ff02
2 changed files with 9 additions and 5 deletions

View File

@ -16,6 +16,7 @@ limitations under the License.
goog.provide('cam.Navigator');
goog.require('cam.object');
goog.require('goog.Uri');
// Navigator intercepts various types of browser navgiations and gives its client an opportunity to decide whether the navigation should be handled with JavaScript or not.
@ -75,10 +76,10 @@ cam.Navigator.prototype.onDidNavigate = function() {};
// @return boolean Whether the navigation was handled locally.
cam.Navigator.prototype.navigate = function(url) {
if (this.dispatchImpl_(url, true)) {
return false;
return true;
}
this.location_.href = url.toString();
return true;
return false;
};
// Handles navigations initiated via clicking a hyperlink.

View File

@ -70,26 +70,29 @@ describe('cam.Navigator', function() {
it('#navigate - no handler', function() {
// We should do network navigation.
navigator.onWillNavigate = function(){};
navigator.navigate(url);
var handledLocally = navigator.navigate(url);
assert.equal(mockLocation.href, url.toString());
assert.equal(mockHistory.states.length, 1);
assert.equal(handledLocally, false);
});
it('#navigate - handler returns false', function() {
// Both handlers should get called, we should do network navigation.
navigator.navigate(url);
var handledLocally = navigator.navigate(url);
assert.equal(handler.lastURL, url);
assert.equal(mockLocation.href, url.toString());
assert.equal(mockHistory.states.length, 1);
assert.equal(handledLocally, false);
});
it('#navigate - handler returns true', function() {
// Both handlers should get called, we should do pushState() navigation.
handler.returnsTrue = true;
navigator.navigate(url);
var handledLocally = navigator.navigate(url);
assert.equal(handler.lastURL, url);
assert.equal(mockLocation.href, '');
assert.deepEqual(mockHistory.states, [{state:{}, url:''}, {state:{}, url:url.toString()}]);
assert.equal(handledLocally, true);
});
it('#handleClick_ - handled', function() {