Skip to content

Commit

Permalink
Add about:studies tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Mikulski committed Jun 13, 2017
1 parent 53c8aa6 commit ee5cae9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
3 changes: 1 addition & 2 deletions recipe-client-addon/lib/AboutStudies.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>about:studies</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<body id="about-studies-page">
<h1>about:studies</h1>
<p>Hello world!</p>
</body>
Expand Down
2 changes: 1 addition & 1 deletion recipe-client-addon/lib/AboutStudiesProtocol.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ this.EXPORTED_SYMBOLS = ["AboutStudiesProtocol"];

/**
* Required data for registering a protocol handler. This data is referred to
* both when creating the new channel, as well as actually registering the
* when creating the new channel, as well as actually registering the
* component factory.
*/
const protocolInfo = {
Expand Down
1 change: 1 addition & 0 deletions recipe-client-addon/test/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ support-files =
[browser_ClientEnvironment.js]
[browser_ShieldRecipeClient.js]
[browser_PreferenceExperiments.js]
[browser_AboutStudiesProtocol.js]
64 changes: 64 additions & 0 deletions recipe-client-addon/test/browser/browser_AboutStudiesProtocol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";

Cu.import("resource://shield-recipe-client/lib/SandboxManager.jsm", this);
Cu.import("resource://shield-recipe-client/lib/AboutStudiesProtocol.jsm", this);

const sandboxManager = new SandboxManager();
sandboxManager.addHold("test running");

// Test un/register for basic errors.
add_task(async function() {
let passed = true;
try {
AboutStudiesProtocol.register();
AboutStudiesProtocol.unregister();
} catch (e) {
passed = false;
}
Assert.ok(passed, "Did not throw when un/registering about:studies");
});

// Test 'one-sided' protocol unregistration. Determines if the protocol throws an
// error if it is asked to unregister while not already registered.
add_task(async function() {
let passed = true;
try {
AboutStudiesProtocol.unregister();
} catch (e) {
passed = false;
}
Assert.ok(passed, "Did not throw when removing a non-registered about:studies protocol");
});

// Test to determine the `about:studies` page is actually loaded and displayed in
// the browser.
add_task(async function() {
AboutStudiesProtocol.register();

await BrowserTestUtils.withNewTab("about:studies", (tab) => {
// Grab the HTMLDocument from the tab's XULDocument. This allows us to
// perform basic DOM searches in the tab to determine if the content matches
// what we expect.
const dom = tab.contentDocument;
const aboutPage = dom.querySelector("#about-studies-page");

// About page should exist, and the content `Hello world!` should be present.
Assert.ok(!!aboutPage, "Found about:studies page");
Assert.equal(aboutPage.querySelector("h1").textContent, "about:studies", "Correct header content.");
Assert.equal(aboutPage.querySelector("p").textContent, "Hello world!", "Correct text content.");
});

AboutStudiesProtocol.unregister();
});

// Cleanup
add_task(async function() {
// Unregister the protocol, just in case.
AboutStudiesProtocol.unregister();

// Make sure the sandbox is clean.
sandboxManager.removeHold("test running");
await sandboxManager.isNuked()
.then(() => ok(true, "sandbox is nuked"))
.catch(e => ok(false, "sandbox is nuked", e));
});

0 comments on commit ee5cae9

Please sign in to comment.