test_accessible_openLink.html (3759B)
1 <!-- This Source Code Form is subject to the terms of the Mozilla Public 2 - License, v. 2.0. If a copy of the MPL was not distributed with this 3 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 4 <!DOCTYPE HTML> 5 <html> 6 <!-- 7 Test that openLink function is called if accessible object property is rendered as a link. 8 --> 9 <head> 10 <meta charset="utf-8"> 11 <title>Accessible component test</title> 12 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 13 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 14 <link rel="stylesheet" href="chrome://devtools/skin/light-theme.css" type="text/css"> 15 </head> 16 <body> 17 <pre id="test"> 18 <script src="head.js" type="application/javascript"></script> 19 <script type="application/javascript"> 20 21 "use strict"; 22 23 window.onload = async function() { 24 try { 25 const { gDevTools } = require("devtools/client/framework/devtools"); 26 const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom"); 27 const { createFactory, createElement } = 28 browserRequire("devtools/client/shared/vendor/react"); 29 const { Provider } = require("devtools/client/shared/vendor/react-redux"); 30 const createStore = require("devtools/client/shared/redux/create-store"); 31 const { Simulate } = 32 browserRequire("devtools/client/shared/vendor/react-dom-test-utils"); 33 const Accessible = createFactory( 34 browserRequire("devtools/client/accessibility/components/Accessible")); 35 36 function testLinkClicked(link, event, expectedUrl, expectedWhere) { 37 const browserWindow = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType); 38 const defaultOpenWebLinkIn = browserWindow.openWebLinkIn; 39 40 const checker = Symbol(); 41 let onClickArgs = checker; 42 browserWindow.openWebLinkIn = (url, where) => { 43 onClickArgs = { url, where }; 44 }; 45 46 Simulate.click(link, event); 47 48 ok(onClickArgs !== checker, "Link was clicked"); 49 is(onClickArgs.url, expectedUrl, "Correct URL is opened"); 50 is(onClickArgs.where, expectedWhere, "URL was opened correctly"); 51 52 browserWindow.openWebLinkIn = defaultOpenWebLinkIn; 53 } 54 55 const a = Accessible({ labelledby: "Test Accessible" }); 56 ok(a, "Should be able to create Accessible instances"); 57 58 let URL = "http://example.com"; 59 const mockStore = createStore((state, action) => 60 action ? { ...state, ...action } : state, 61 { 62 initialState: { 63 details: { 64 DOMNode: {}, 65 accessible: { 66 // This accessible mock has no actorID and should be treated as 67 // destroyed. 68 isDestroyed: () => true, 69 value: URL, 70 } 71 }, 72 ui: { 73 supports: {} 74 } 75 }, 76 } 77 ); 78 const provider = createElement(Provider, { store: mockStore }, a); 79 const accessible = ReactDOM.render(provider, window.document.body); 80 ok(accessible, "Should be able to mount Accessible instances"); 81 82 let link = document.querySelector(".url"); 83 testLinkClicked(link, null, URL, "tab"); 84 85 URL = "non-URL"; 86 await mockStore.dispatch( 87 { 88 type: "update", 89 details: { 90 DOMNode: {}, 91 accessible: { 92 // This accessible mock has no actorID and should be treated as 93 // destroyed. 94 isDestroyed: () => true, 95 value: URL, 96 } 97 } 98 } 99 ); 100 link = document.querySelector(".url"); 101 ok(!link, "Non URL link should not be rendered as a link."); 102 } catch (e) { 103 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); 104 } finally { 105 SimpleTest.finish(); 106 } 107 }; 108 </script> 109 </pre> 110 </body> 111 </html>