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

1) cam.object dep was needed for any of the tests to run
2) fixed the return logic of navigate() to match its doc. Should be of
no consequence though, as afaik this return value is not used anywhere.
3) added tests for 2)

Change-Id: I5c236ab95482b50437f0047d63e42603f754438d
This commit is contained in:
mpl 2015-06-03 16:52:27 +02:00
parent cbec324c6a
commit 8c392e92a0
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() {