Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3587)

Unified Diff: chrome/browser/resources/chromeos/chromevox/walkers/layout_line_walker_test.unitjs

Issue 563773003: Migrate walker tests from upstream ChromeVox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Finish walker tests. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/walkers/layout_line_walker_test.unitjs
diff --git a/chrome/browser/resources/chromeos/chromevox/walkers/layout_line_walker_test.unitjs b/chrome/browser/resources/chromeos/chromevox/walkers/layout_line_walker_test.unitjs
new file mode 100644
index 0000000000000000000000000000000000000000..6005ded809513f8fa407a33d4816eb6f0e1e3f4a
--- /dev/null
+++ b/chrome/browser/resources/chromeos/chromevox/walkers/layout_line_walker_test.unitjs
@@ -0,0 +1,183 @@
+// Copyright 2014 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.
+
+// Include test fixture.
+GEN_INCLUDE(['../testing/chromevox_unittest_base.js']);
+
+/**
+ * Test fixture.
+ * @constructor
+ * @extends {ChromeVoxUnitTestBase}
+ */
+function CvoxLayoutLineWalkerUnitTest() {}
+
+CvoxLayoutLineWalkerUnitTest.prototype = {
+ __proto__: ChromeVoxUnitTestBase.prototype,
+
+ /** @override */
+ closureModuleDeps: [
+ 'cvox.CursorSelection',
+ 'cvox.LayoutLineWalker',
+ 'cvox.TestMsgs',
+ ],
+
+ /** @override */
+ setUp: function() {
+ this.loadDoc(function() {/*!
+ <div id='1'>
+ <p id='a'>Demonstrating that in-line links like
+ <a id='aa' href="google.com">google</a>
+ are considered a single layout line.
+ </p>
+ <p id='b'>
+ This includes a paragraph that has a lot of text like this one.
+ <a id='bb' href="wikipedia.com">Wikipedia</a>
+ is a great example of a site that this walker becomes valuable. Braille
+ also benefits greatly from<br>
+ this type of formatting since some displays
+ can handle lots of text like 80 cell displays!
+ </p>
+ </div>
+ */});
+ cvox.ChromeVox.msgs = new cvox.TestMsgs();
+ this.walker = new cvox.LayoutLineWalker();
+
+ this.a = cvox.CursorSelection.fromNode(document.getElementById('a'));
dmazzoni 2014/09/12 15:53:27 nit: we're using $('a') in the other tests, since
+ this.aa = cvox.CursorSelection.fromNode(document.getElementById('aa'));
+ this.b = cvox.CursorSelection.fromNode(document.getElementById('b'));
+ this.bb = cvox.CursorSelection.fromNode(document.getElementById('bb'));
+
+ this.line1Text = 'Demonstrating that in-line links like google are' +
+ ' considered a single layout line.';
+
+ this.line2Text = 'This includes a paragraph that has a lot of text' +
+ ' like this one. Wikipedia is a great example of a site that this' +
+ ' walker becomes valuable. Braille also benefits greatly from';
+
+ this.line3Text =
+ 'this type of formatting since some displays can handle lots of' +
+ ' text like 80 cell displays!';
+
+ this.line1Description =
+ [{'context': '', 'text': 'Demonstrating that in-line links like',
+ 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null,
+ 'hint': '', 'category': null},
+ {'context': '', 'text': 'google', 'userValue': '', 'annotation': 'Link',
+ 'earcons': [cvox.AbstractEarcons.LINK], 'personality': null,
+ hint: '', 'category': null},
+ {'context': '', 'text': 'are considered a single layout line.',
+ 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null,
+ 'hint': '', 'category': null}];
+
+ this.line2Description =
+ [{'context': '', 'text':
+ 'This includes a paragraph that has a lot of text like this one.',
+ 'userValue': '', 'annotation': '', 'earcons': [], 'personality': null,
+ 'hint': '', 'category': null},
+ {'context': '',
+ 'text': 'Wikipedia',
+ 'userValue': '',
+ 'annotation': 'Link',
+ 'earcons': [cvox.AbstractEarcons.LINK],
+ 'personality': null,
+ 'hint': '', 'category': null},
+ {'context': '', 'text':
+ 'is a great example of a site that this walker becomes valuable.' +
+ ' Braille also benefits greatly from', 'userValue': '',
+ 'annotation': '', 'earcons': [], 'personality': null,
+ 'hint': '', 'category': null}];
+ }
+};
+
+TEST_F('CvoxLayoutLineWalkerUnitTest', 'Sync', function() {
+ var sel = cvox.CursorSelection.fromNode($('1'));
+ sel = this.walker.sync(sel);
+ assertEquals(this.line1Text, sel.getText());
+
+ sel = this.walker.sync(this.a);
+ assertEquals(this.line1Text, sel.getText());
+
+ sel = this.walker.sync(this.aa);
+ assertEquals(this.line1Text, sel.getText());
+
+ sel = this.walker.sync(this.b);
+ assertEquals(this.line2Text, sel.getText());
+
+ sel = this.walker.sync(this.bb);
+ assertEquals(this.line2Text, sel.getText());
+
+ // Reversed sync.
+ sel = this.walker.sync(this.a).setReversed(true);
+ assertEquals(this.line1Text, sel.getText());
+
+ sel = this.walker.sync(this.aa).setReversed(true);
+ assertEquals(this.line1Text, sel.getText());
+
+ sel = this.walker.sync(this.b).setReversed(true);
+ assertEquals(this.line2Text, sel.getText());
+
+ sel = this.walker.sync(this.bb).setReversed(true);
+ assertEquals(this.line2Text, sel.getText());
+});
+
+/** Tests description of valid selections. */
+TEST_F('CvoxLayoutLineWalkerUnitTest', 'Description', function() {
+ var sel = this.walker.sync(this.a);
+ assertEqualsJSON(this.line1Description,
+ this.walker.getDescription(sel, sel));
+
+ var sel = this.walker.sync(this.b);
+ assertEqualsJSON(this.line2Description, this.walker.getDescription(sel, sel));
+});
+
+
+/** Tests back/forward movement. */
+TEST_F('CvoxLayoutLineWalkerUnitTest', 'BackForward', function() {
+ var sel = this.walker.sync(this.a);
+
+ // Beginning of second line.
+ sel = this.walker.next(sel);
+ assertEquals(Text, sel.start.node.constructor);
+ assertEquals(this.b.start.node.id, sel.start.node.parentNode.id);
+ assertEquals(null, sel.start.node.previousSibling);
+ assertEquals(this.bb.start.node.id, sel.start.node.nextSibling.id);
+
+ // This offset is expected because the index takes into account whitespace
+ // which is retained from the actual source.
+ assertEquals(9, sel.start.index);
+
+ // End of second line.
+ assertEquals(Text, sel.end.node.constructor);
+ assertEquals(this.b.end.node.id, sel.end.node.parentNode.id);
+ assertEquals(HTMLBRElement, sel.end.node.nextSibling.constructor);
+ assertEquals(this.bb.start.node.id, sel.end.node.previousSibling.id);
+ assertEquals(115, sel.end.index);
+
+ // Last line.
+ var last = this.walker.next(sel);
+ assertEquals(this.line3Text, last.getText());
+
+ // Wrap.
+ assertEquals(null, this.walker.next(last));
+
+ // Reverse.
+ sel = last.setReversed(true);
+
+ // Second line.
+ sel = this.walker.next(sel);
+ assertEquals(this.line2Text, sel.getText());
+
+ // Next always returns an unreversed selection for line granularity. Reverse
+ // it to move backward.
+ sel.setReversed(true);
+
+ // First line.
+ sel = this.walker.next(sel);
+ assertEquals(this.line1Text, sel.getText());
+
+ // Wrap.
+ sel.setReversed(true);
+ sel = this.walker.next(sel);
+ assertEquals(null, sel);
+});

Powered by Google App Engine
This is Rietveld 408576698