Commit 9781ff27 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

Revert "Refactor Reader Mode's JavaScript tests to use Mocha."

This reverts commit 7de90169.

Reason for revert: Suspicious to have broken DomDistillerViewerSourceBrowserTest.UISetsPrefs in browser_tests.
https://ci.chromium.org/p/chromium/builders/ci/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%281%29/37476


Original change's description:
> Refactor Reader Mode's JavaScript tests to use Mocha.
> 
> The tests did not previously use an established test framework, making
> tasks like executing certain code before or after every test and testing
> asynchronous code more difficult. It should also be easier for
> developers familiar with JavaScript testing in general and WebUI testing
> in particular to read and write JavaScript tests for DOM Distiller and
> Reader Mode.
> 
> Follow-up work includes replacing the custom assert methods with Chai,
> as well as writing more tests to cover existing functionality.
> 
> Bug: 1027612
> Change-Id: I39acc923a0424881d2694281d9aa0323c8f9a913
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1992504
> Reviewed-by: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
> Commit-Queue: Aran Gilman <gilmanmh@google.com>
> Cr-Commit-Position: refs/heads/master@{#762551}

TBR=wychen@chromium.org,gilmanmh@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1027612
Change-Id: I78b6b82e98c8f47951ab88e2056595de878f1ab1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166219Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762720}
parent 7104027b
...@@ -561,7 +561,6 @@ if (!is_ios && !is_fuchsia) { ...@@ -561,7 +561,6 @@ if (!is_ios && !is_fuchsia) {
"security_state/content/testdata/", "security_state/content/testdata/",
"//content/test/data/", "//content/test/data/",
"//third_party/dom_distiller_js/dist/test/data/", "//third_party/dom_distiller_js/dist/test/data/",
"//third_party/mocha",
] ]
deps = [ deps = [
......
...@@ -22,6 +22,22 @@ ...@@ -22,6 +22,22 @@
namespace dom_distiller { namespace dom_distiller {
namespace { namespace {
base::Value ExecuteJsScript(content::WebContents* web_contents,
const std::string& script) {
base::Value result;
base::RunLoop run_loop;
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
base::UTF8ToUTF16(script),
base::BindOnce(
[](base::Closure callback, base::Value* out, base::Value result) {
(*out) = std::move(result);
callback.Run();
},
run_loop.QuitClosure(), &result));
run_loop.Run();
return result;
}
class DistilledPageJsTest : public content::ContentBrowserTest { class DistilledPageJsTest : public content::ContentBrowserTest {
protected: protected:
explicit DistilledPageJsTest() explicit DistilledPageJsTest()
...@@ -37,13 +53,14 @@ class DistilledPageJsTest : public content::ContentBrowserTest { ...@@ -37,13 +53,14 @@ class DistilledPageJsTest : public content::ContentBrowserTest {
distilled_page_ = SetUpTestServerWithDistilledPage(embedded_test_server()); distilled_page_ = SetUpTestServerWithDistilledPage(embedded_test_server());
} }
void LoadAndExecuteTestScript(const std::string& file) { void LoadAndExecuteTestScript(const std::string& file,
const std::string& fixture_name) {
distilled_page_->AppendScriptFile(file); distilled_page_->AppendScriptFile(file);
distilled_page_->Load(embedded_test_server(), shell()->web_contents()); distilled_page_->Load(embedded_test_server(), shell()->web_contents());
bool allTestsPassed; const base::Value result = ExecuteJsScript(
ASSERT_TRUE(content::ExecuteScriptAndExtractBool( shell()->web_contents(), base::StrCat({fixture_name, ".run()"}));
shell()->web_contents(), "mocha.run()", &allTestsPassed)); ASSERT_EQ(base::Value::Type::BOOLEAN, result.type());
EXPECT_TRUE(allTestsPassed); EXPECT_TRUE(result.GetBool());
} }
std::unique_ptr<FakeDistilledPage> distilled_page_; std::unique_ptr<FakeDistilledPage> distilled_page_;
...@@ -55,7 +72,7 @@ class DistilledPageJsTest : public content::ContentBrowserTest { ...@@ -55,7 +72,7 @@ class DistilledPageJsTest : public content::ContentBrowserTest {
#define MAYBE_Pinch Pinch #define MAYBE_Pinch Pinch
#endif #endif
IN_PROC_BROWSER_TEST_F(DistilledPageJsTest, MAYBE_Pinch) { IN_PROC_BROWSER_TEST_F(DistilledPageJsTest, MAYBE_Pinch) {
LoadAndExecuteTestScript("pinch_tester.js"); LoadAndExecuteTestScript("pinch_tester.js", "pinchtest");
} }
} // namespace } // namespace
......
...@@ -39,12 +39,10 @@ const char* kDistilledPagePath = "/distilled_page.html"; ...@@ -39,12 +39,10 @@ const char* kDistilledPagePath = "/distilled_page.html";
void SetUpTestServerWithoutStarting(EmbeddedTestServer* server) { void SetUpTestServerWithoutStarting(EmbeddedTestServer* server) {
FilePath root_dir; FilePath root_dir;
PathService::Get(base::DIR_SOURCE_ROOT, &root_dir); PathService::Get(base::DIR_SOURCE_ROOT, &root_dir);
server->ServeFilesFromDirectory(
root_dir.AppendASCII("components/dom_distiller/core/javascript"));
server->ServeFilesFromDirectory( server->ServeFilesFromDirectory(
root_dir.AppendASCII("components/test/data/dom_distiller")); root_dir.AppendASCII("components/test/data/dom_distiller"));
server->ServeFilesFromDirectory(root_dir.AppendASCII("third_party/mocha")); server->ServeFilesFromDirectory(
root_dir.AppendASCII("components/dom_distiller/core/javascript"));
} }
} // namespace } // namespace
...@@ -60,8 +58,6 @@ FakeDistilledPage::FakeDistilledPage(EmbeddedTestServer* server) ...@@ -60,8 +58,6 @@ FakeDistilledPage::FakeDistilledPage(EmbeddedTestServer* server)
// DomDistillerRequestViewBase::SendCommonJavaScript(); however, this method // DomDistillerRequestViewBase::SendCommonJavaScript(); however, this method
// is impractical to use in testing. // is impractical to use in testing.
AppendScriptFile("dom_distiller_viewer.js"); AppendScriptFile("dom_distiller_viewer.js");
AppendScriptFile("mocha.js");
AppendScriptFile("test_util.js");
} }
FakeDistilledPage::~FakeDistilledPage() = default; FakeDistilledPage::~FakeDistilledPage() = default;
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO(gilmanmh): Consider replacing this with dispatched touch events.
class Touch { class Touch {
constructor() { constructor() {
this.points = {}; this.points = {};
...@@ -45,61 +44,64 @@ class Touch { ...@@ -45,61 +44,64 @@ class Touch {
} }
} }
// TODO(gilmanmh): Replace these helpers with Chai's equivalents. class PinchTest {
function assertTrue(condition, message) { /** @private */
if (!condition) { assertTrue_(condition, message) {
message = message || 'Assertion failed'; if (!condition) {
console.trace(); message = message || 'Assertion failed';
throw new Error(message); console.trace();
throw new Error(message);
}
} }
}
function assertClose(a, b, message) { /** @private */
if (Math.abs(a - b) > 1e-5) { assertClose_(a, b, message) {
message = message || 'Assertion failed'; if (Math.abs(a - b) > 1e-5) {
console.log('"', a, '" and "', b, '" are not close.'); message = message || 'Assertion failed';
console.trace(); console.log('"', a, '" and "', b, '" are not close.');
throw new Error(message); console.trace();
} throw new Error(message);
} }
function isEquivalent(a, b) {
// Create arrays of property names
const aProps = Object.getOwnPropertyNames(a);
const bProps = Object.getOwnPropertyNames(b);
// If number of properties is different,
// objects are not equivalent
if (aProps.length != bProps.length) {
return false;
} }
for (let i = 0; i < aProps.length; i++) { /** @private */
const propName = aProps[i]; isEquivalent_(a, b) {
// Create arrays of property names
const aProps = Object.getOwnPropertyNames(a);
const bProps = Object.getOwnPropertyNames(b);
// If values of same property are not equal, // If number of properties is different,
// objects are not equivalent // objects are not equivalent
if (a[propName] !== b[propName]) { if (aProps.length != bProps.length) {
return false; return false;
} }
}
// If we made it this far, objects for (let i = 0; i < aProps.length; i++) {
// are considered equivalent const propName = aProps[i];
return true;
} // If values of same property are not equal,
// objects are not equivalent
if (a[propName] !== b[propName]) {
return false;
}
}
function assertEqual(a, b, message) { // If we made it this far, objects
if (!isEquivalent(a, b)) { // are considered equivalent
message = message || 'Assertion failed'; return true;
console.log('"', a, '" and "', b, '" are not equal'); }
console.trace();
throw new Error(message); /** @private */
assertEqual_(a, b, message) {
if (!this.isEquivalent_(a, b)) {
message = message || 'Assertion failed';
console.log('"', a, '" and "', b, '" are not equal');
console.trace();
throw new Error(message);
}
} }
}
suite('Pincher', function() { testZoomOut() {
test('Zoom Out', function() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
...@@ -107,57 +109,57 @@ suite('Pincher', function() { ...@@ -107,57 +109,57 @@ suite('Pincher', function() {
let oldState = pincher.status(); let oldState = pincher.status();
t.addTouchPoint(100, 100); t.addTouchPoint(100, 100);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(300, 300); t.addTouchPoint(300, 300);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
// Make sure extra move event doesn't change state // Make sure extra move event doesn't change state
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.updateTouchPoint(0, 150, 150); t.updateTouchPoint(0, 150, 150);
t.updateTouchPoint(1, 250, 250); t.updateTouchPoint(1, 250, 250);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertTrue(pincher.status().clampedScale < 0.9); this.assertTrue_(pincher.status().clampedScale < 0.9);
// Make sure end event doesn't change state // Make sure end event doesn't change state
oldState = pincher.status(); oldState = pincher.status();
t.releaseTouchPoint(1); t.releaseTouchPoint(1);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
}); }
test('Zoom In', function() { testZoomIn() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
let oldState = pincher.status(); let oldState = pincher.status();
t.addTouchPoint(150, 150); t.addTouchPoint(150, 150);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(250, 250); t.addTouchPoint(250, 250);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.updateTouchPoint(0, 100, 100); t.updateTouchPoint(0, 100, 100);
t.updateTouchPoint(1, 300, 300); t.updateTouchPoint(1, 300, 300);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertTrue(pincher.status().clampedScale > 1.1); this.assertTrue_(pincher.status().clampedScale > 1.1);
oldState = pincher.status(); oldState = pincher.status();
t.releaseTouchPoint(1); t.releaseTouchPoint(1);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
}); }
test('Zomm Out And Pan', function() { testZoomOutAndPan() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
t.addTouchPoint(100, 100); t.addTouchPoint(100, 100);
...@@ -175,12 +177,12 @@ suite('Pincher', function() { ...@@ -175,12 +177,12 @@ suite('Pincher', function() {
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertClose(pincher.status().shiftX, 10); this.assertClose_(pincher.status().shiftX, 10);
assertClose(pincher.status().shiftY, -5); this.assertClose_(pincher.status().shiftY, -5);
assertTrue(pincher.status().clampedScale < 0.9); this.assertTrue_(pincher.status().clampedScale < 0.9);
}); }
test('Reversible', function() { testReversible() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
t.addTouchPoint(100, 100); t.addTouchPoint(100, 100);
...@@ -205,26 +207,26 @@ suite('Pincher', function() { ...@@ -205,26 +207,26 @@ suite('Pincher', function() {
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertClose(pincher.status().clampedScale, 1); this.assertClose_(pincher.status().clampedScale, 1);
}); }
test('Multitouch Zoom Out', function() { testMultitouchZoomOut() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
let oldState = pincher.status(); let oldState = pincher.status();
t.addTouchPoint(100, 100); t.addTouchPoint(100, 100);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(300, 300); t.addTouchPoint(300, 300);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(100, 300); t.addTouchPoint(100, 300);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(300, 100); t.addTouchPoint(300, 100);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
// Multi-touch zoom out. // Multi-touch zoom out.
t.updateTouchPoint(0, 150, 150); t.updateTouchPoint(0, 150, 150);
...@@ -236,60 +238,60 @@ suite('Pincher', function() { ...@@ -236,60 +238,60 @@ suite('Pincher', function() {
oldState = pincher.status(); oldState = pincher.status();
t.releaseTouchPoint(3); t.releaseTouchPoint(3);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.releaseTouchPoint(2); t.releaseTouchPoint(2);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.releaseTouchPoint(1); t.releaseTouchPoint(1);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
assertTrue(pincher.status().clampedScale < 0.9); this.assertTrue_(pincher.status().clampedScale < 0.9);
}); }
test('Zoom Out Then Multi', function() { testZoomOutThenMulti() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
let oldState = pincher.status(); let oldState = pincher.status();
t.addTouchPoint(100, 100); t.addTouchPoint(100, 100);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(300, 300); t.addTouchPoint(300, 300);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
// Zoom out. // Zoom out.
t.updateTouchPoint(0, 150, 150); t.updateTouchPoint(0, 150, 150);
t.updateTouchPoint(1, 250, 250); t.updateTouchPoint(1, 250, 250);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertTrue(pincher.status().clampedScale < 0.9); this.assertTrue_(pincher.status().clampedScale < 0.9);
// Make sure adding and removing more point doesn't change state // Make sure adding and removing more point doesn't change state
oldState = pincher.status(); oldState = pincher.status();
t.addTouchPoint(600, 600); t.addTouchPoint(600, 600);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.releaseTouchPoint(2); t.releaseTouchPoint(2);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
// More than two fingers. // More than two fingers.
t.addTouchPoint(150, 250); t.addTouchPoint(150, 250);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
t.addTouchPoint(250, 150); t.addTouchPoint(250, 150);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.updateTouchPoint(0, 100, 100); t.updateTouchPoint(0, 100, 100);
t.updateTouchPoint(1, 300, 300); t.updateTouchPoint(1, 300, 300);
t.updateTouchPoint(2, 100, 300); t.updateTouchPoint(2, 100, 300);
t.updateTouchPoint(3, 300, 100); t.updateTouchPoint(3, 300, 100);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertClose(pincher.status().scale, 1); this.assertClose_(pincher.status().scale, 1);
oldState = pincher.status(); oldState = pincher.status();
t.releaseTouchPoint(3); t.releaseTouchPoint(3);
...@@ -297,10 +299,10 @@ suite('Pincher', function() { ...@@ -297,10 +299,10 @@ suite('Pincher', function() {
t.releaseTouchPoint(1); t.releaseTouchPoint(1);
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchEnd(t.events()); pincher.handleTouchEnd(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
}); }
test('Cancel', function() { testCancel() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
...@@ -311,13 +313,13 @@ suite('Pincher', function() { ...@@ -311,13 +313,13 @@ suite('Pincher', function() {
t.updateTouchPoint(0, 150, 150); t.updateTouchPoint(0, 150, 150);
t.updateTouchPoint(1, 250, 250); t.updateTouchPoint(1, 250, 250);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertTrue(pincher.status().clampedScale < 0.9); this.assertTrue_(pincher.status().clampedScale < 0.9);
const oldState = pincher.status(); const oldState = pincher.status();
t.releaseTouchPoint(1); t.releaseTouchPoint(1);
t.releaseTouchPoint(0); t.releaseTouchPoint(0);
pincher.handleTouchCancel(t.events()); pincher.handleTouchCancel(t.events());
assertEqual(oldState, pincher.status()); this.assertEqual_(oldState, pincher.status());
t.addTouchPoint(150, 150); t.addTouchPoint(150, 150);
pincher.handleTouchStart(t.events()); pincher.handleTouchStart(t.events());
...@@ -326,10 +328,10 @@ suite('Pincher', function() { ...@@ -326,10 +328,10 @@ suite('Pincher', function() {
t.updateTouchPoint(0, 100, 100); t.updateTouchPoint(0, 100, 100);
t.updateTouchPoint(1, 300, 300); t.updateTouchPoint(1, 300, 300);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertClose(pincher.status().clampedScale, 1); this.assertClose_(pincher.status().clampedScale, 1);
}); }
test('Singularity', function() { testSingularity() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
...@@ -340,14 +342,14 @@ suite('Pincher', function() { ...@@ -340,14 +342,14 @@ suite('Pincher', function() {
t.updateTouchPoint(0, 150, 150); t.updateTouchPoint(0, 150, 150);
t.updateTouchPoint(1, 50, 50); t.updateTouchPoint(1, 50, 50);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertTrue(pincher.status().clampedScale > 1.1); this.assertTrue_(pincher.status().clampedScale > 1.1);
assertTrue(pincher.status().clampedScale < 100); this.assertTrue_(pincher.status().clampedScale < 100);
assertTrue(pincher.status().scale < 100); this.assertTrue_(pincher.status().scale < 100);
pincher.handleTouchCancel(); pincher.handleTouchCancel();
}); }
test('Min Span', function() { testMinSpan() {
pincher.reset(); pincher.reset();
const t = new Touch(); const t = new Touch();
...@@ -358,17 +360,17 @@ suite('Pincher', function() { ...@@ -358,17 +360,17 @@ suite('Pincher', function() {
t.updateTouchPoint(0, 100, 100); t.updateTouchPoint(0, 100, 100);
t.updateTouchPoint(1, 100, 100); t.updateTouchPoint(1, 100, 100);
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
assertTrue(pincher.status().clampedScale < 0.9); this.assertTrue_(pincher.status().clampedScale < 0.9);
assertTrue(pincher.status().clampedScale > 0); this.assertTrue_(pincher.status().clampedScale > 0);
assertTrue(pincher.status().scale > 0); this.assertTrue_(pincher.status().scale > 0);
pincher.handleTouchCancel(); pincher.handleTouchCancel();
}); }
test('Font Scaling', function() { testFontScaling() {
pincher.reset(); pincher.reset();
useFontScaling(1.5); useFontScaling(1.5);
assertClose(pincher.status().clampedScale, 1.5); this.assertClose_(pincher.status().clampedScale, 1.5);
let t = new Touch(); let t = new Touch();
...@@ -385,11 +387,12 @@ suite('Pincher', function() { ...@@ -385,11 +387,12 @@ suite('Pincher', function() {
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
// Verify scale is smaller. // Verify scale is smaller.
assertTrue(pincher.status().clampedScale < 0.9 * oldState.clampedScale); this.assertTrue_(
pincher.status().clampedScale < 0.9 * oldState.clampedScale);
pincher.handleTouchCancel(); pincher.handleTouchCancel();
useFontScaling(0.8); useFontScaling(0.8);
assertClose(pincher.status().clampedScale, 0.8); this.assertClose_(pincher.status().clampedScale, 0.8);
// Start touch. // Start touch.
t = new Touch(); t = new Touch();
...@@ -405,7 +408,25 @@ suite('Pincher', function() { ...@@ -405,7 +408,25 @@ suite('Pincher', function() {
pincher.handleTouchMove(t.events()); pincher.handleTouchMove(t.events());
// Verify scale is larger. // Verify scale is larger.
assertTrue(pincher.status().clampedScale > 1.1 * oldState.clampedScale); this.assertTrue_(
pincher.status().clampedScale > 1.1 * oldState.clampedScale);
pincher.handleTouchCancel(); pincher.handleTouchCancel();
}); }
});
run() {
this.testZoomOut();
this.testZoomIn();
this.testZoomOutAndPan();
this.testReversible();
this.testMultitouchZoomOut();
this.testZoomOutThenMulti();
this.testCancel();
this.testSingularity();
this.testMinSpan();
this.testFontScaling();
pincher.reset();
return true;
}
}
const pinchtest = new PinchTest;
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Based on BrowserTestReporter() in //chrome/test/data/webui/mocha_adapter.js
// TODO(crbug.com/1027612): Look into using that class directly.
function TestReporter(runner) {
let passes = 0;
let failures = 0;
runner.on('pass', function(test) {
passes++;
});
runner.on('fail', function(test, err) {
failures++;
let message = 'Mocha test failed: ' + test.fullTitle() + '\n';
// Remove unhelpful mocha lines from stack trace.
if (err.stack) {
const stack = err.stack.split('\n');
for (let i = 0; i < stack.length; i++) {
if (stack[i].indexOf('mocha.js:') == -1) {
message += stack[i] + '\n';
}
}
} else {
message += err.toString();
}
console.error(message);
});
runner.on('end', function() {
window.domAutomationController.send(failures === 0 && passes > 0);
});
}
mocha.setup({
ui: 'tdd',
reporter: TestReporter,
enableTimeouts: false,
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment