function testNavigate() {
    var mockWindow = new MockWindow(100, 100);
    var mockSizer = new MockSizer();
    var mockCallback = new MockViewportChangedCallback();
    var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
                                function() {}, function() {}, function() {},
                                0, 1, 0);

    var paramsParser = new OpenPDFParamsParser(function(message) {
      if (message.namedDestination == 'US')
        paramsParser.onNamedDestinationReceived(0);
      else if (message.namedDestination == 'UY')
        paramsParser.onNamedDestinationReceived(2);
      else
        paramsParser.onNamedDestinationReceived(-1);
    });
    var url = "http://xyz.pdf";

    var navigatorDelegate = new MockNavigatorDelegate();
    var navigator = new Navigator(url, viewport, paramsParser,
                                  navigatorDelegate);

    var documentDimensions = new MockDocumentDimensions();
    documentDimensions.addPage(100, 100);
    documentDimensions.addPage(200, 200);
    documentDimensions.addPage(100, 400);
    viewport.setDocumentDimensions(documentDimensions);
    viewport.setZoom(1);

    mockCallback.reset();
    // This should move viewport to page 0.
    navigator.navigate(url + "#US",
        Navigator.WindowOpenDisposition.CURRENT_TAB);
    chrome.test.assertTrue(mockCallback.wasCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(0, viewport.position.y);

    mockCallback.reset();
    navigatorDelegate.reset();
    // This should open "http://xyz.pdf#US" in a new tab. So current tab
    // viewport should not update and viewport position should remain same.
    navigator.navigate(url + "#US",
        Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB);
    chrome.test.assertFalse(mockCallback.wasCalled);
    chrome.test.assertTrue(navigatorDelegate.navigateInNewTabCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(0, viewport.position.y);

    mockCallback.reset();
    // This should move viewport to page 2.
    navigator.navigate(url + "#UY",
        Navigator.WindowOpenDisposition.CURRENT_TAB);
    chrome.test.assertTrue(mockCallback.wasCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(300, viewport.position.y);

    mockCallback.reset();
    navigatorDelegate.reset();
    // #ABC is not a named destination in the page so viewport should not
    // update and viewport position should remain same. As this link will open
    // in the same tab.
    navigator.navigate(url + "#ABC",
        Navigator.WindowOpenDisposition.CURRENT_TAB);
    chrome.test.assertFalse(mockCallback.wasCalled);
    chrome.test.assertTrue(navigatorDelegate.navigateInCurrentTabCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(300, viewport.position.y);

    chrome.test.succeed();
  }
/**
   * Test navigation within the page, opening a url in the same tab and
   * opening a url in a new tab.
   */
Test navigation within the page, opening a url in the same tab and
opening a url in a new tab.
Test navigation within the page opening a url in the same tab and opening a url in a new tab .
function testNavigate() {
    var mockWindow = new MockWindow(100, 100);
    var mockSizer = new MockSizer();
    var mockCallback = new MockViewportChangedCallback();
    var viewport = new Viewport(mockWindow, mockSizer, mockCallback.callback,
                                function() {}, function() {}, function() {},
                                0, 1, 0);
    var paramsParser = new OpenPDFParamsParser(function(message) {
      if (message.namedDestination == 'US')
        paramsParser.onNamedDestinationReceived(0);
      else if (message.namedDestination == 'UY')
        paramsParser.onNamedDestinationReceived(2);
      else
        paramsParser.onNamedDestinationReceived(-1);
    });
    var url = "http://xyz.pdf";
    var navigatorDelegate = new MockNavigatorDelegate();
    var navigator = new Navigator(url, viewport, paramsParser,
                                  navigatorDelegate);
    var documentDimensions = new MockDocumentDimensions();
    documentDimensions.addPage(100, 100);
    documentDimensions.addPage(200, 200);
    documentDimensions.addPage(100, 400);
    viewport.setDocumentDimensions(documentDimensions);
    viewport.setZoom(1);
    mockCallback.reset();
    navigator.navigate(url + "#US",
        Navigator.WindowOpenDisposition.CURRENT_TAB);
    chrome.test.assertTrue(mockCallback.wasCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(0, viewport.position.y);
    mockCallback.reset();
    navigatorDelegate.reset();
    navigator.navigate(url + "#US",
        Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB);
    chrome.test.assertFalse(mockCallback.wasCalled);
    chrome.test.assertTrue(navigatorDelegate.navigateInNewTabCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(0, viewport.position.y);
    mockCallback.reset();
    navigator.navigate(url + "#UY",
        Navigator.WindowOpenDisposition.CURRENT_TAB);
    chrome.test.assertTrue(mockCallback.wasCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(300, viewport.position.y);
    mockCallback.reset();
    navigatorDelegate.reset();
    navigator.navigate(url + "#ABC",
        Navigator.WindowOpenDisposition.CURRENT_TAB);
    chrome.test.assertFalse(mockCallback.wasCalled);
    chrome.test.assertTrue(navigatorDelegate.navigateInCurrentTabCalled);
    chrome.test.assertEq(0, viewport.position.x);
    chrome.test.assertEq(300, viewport.position.y);
    chrome.test.succeed();
  }
function testNavigate ( ) { var mockWindow = new MockWindow ( 100 , 100 ) ; var mockSizer = new MockSizer ( ) ; var mockCallback = new MockViewportChangedCallback ( ) ; var viewport = new Viewport ( mockWindow , mockSizer , mockCallback . callback , function ( ) { } , function ( ) { } , function ( ) { } , 0 , 1 , 0 ) ; var paramsParser = new OpenPDFParamsParser ( function ( message ) { if ( message . namedDestination == 'US' ) paramsParser . onNamedDestinationReceived ( 0 ) ; else if ( message . namedDestination == 'UY' ) paramsParser . onNamedDestinationReceived ( 2 ) ; else paramsParser . onNamedDestinationReceived ( - 1 ) ; } ) ; var url = "http://xyz.pdf" ; var navigatorDelegate = new MockNavigatorDelegate ( ) ; var navigator = new Navigator ( url , viewport , paramsParser , navigatorDelegate ) ; var documentDimensions = new MockDocumentDimensions ( ) ; documentDimensions . addPage ( 100 , 100 ) ; documentDimensions . addPage ( 200 , 200 ) ; documentDimensions . addPage ( 100 , 400 ) ; viewport . setDocumentDimensions ( documentDimensions ) ; viewport . setZoom ( 1 ) ; mockCallback . reset ( ) ; navigator . navigate ( url + "#US" , Navigator . WindowOpenDisposition . CURRENT_TAB ) ; chrome . test . assertTrue ( mockCallback . wasCalled ) ; chrome . test . assertEq ( 0 , viewport . position . x ) ; chrome . test . assertEq ( 0 , viewport . position . y ) ; mockCallback . reset ( ) ; navigatorDelegate . reset ( ) ; navigator . navigate ( url + "#US" , Navigator . WindowOpenDisposition . NEW_BACKGROUND_TAB ) ; chrome . test . assertFalse ( mockCallback . wasCalled ) ; chrome . test . assertTrue ( navigatorDelegate . navigateInNewTabCalled ) ; chrome . test . assertEq ( 0 , viewport . position . x ) ; chrome . test . assertEq ( 0 , viewport . position . y ) ; mockCallback . reset ( ) ; navigator . navigate ( url + "#UY" , Navigator . WindowOpenDisposition . CURRENT_TAB ) ; chrome . test . assertTrue ( mockCallback . wasCalled ) ; chrome . test . assertEq ( 0 , viewport . position . x ) ; chrome . test . assertEq ( 300 , viewport . position . y ) ; mockCallback . reset ( ) ; navigatorDelegate . reset ( ) ; navigator . navigate ( url + "#ABC" , Navigator . WindowOpenDisposition . CURRENT_TAB ) ; chrome . test . assertFalse ( mockCallback . wasCalled ) ; chrome . test . assertTrue ( navigatorDelegate . navigateInCurrentTabCalled ) ; chrome . test . assertEq ( 0 , viewport . position . x ) ; chrome . test . assertEq ( 300 , viewport . position . y ) ; chrome . test . succeed ( ) ; }
Test navigation within the page, opening a url in the same tab and
 opening a url in a new tab.
Test navigation within the page opening a url in the same tab and opening a url in a new tab .
// This should move viewport to page 0. // This should open "http://xyz.pdf#US" in a new tab. So current tab // viewport should not update and viewport position should remain same. // This should move viewport to page 2. // #ABC is not a named destination in the page so viewport should not // update and viewport position should remain same. As this link will open // in the same tab.