Added new walnut test suite that checks the precedence of the
selection of a browser-object to apply to a command.
---
 modules/walnut.js                         |    6 +++
 tests/simple/browser-object-precedence.js |   52 +++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 tests/simple/browser-object-precedence.js

diff --git a/modules/walnut.js b/modules/walnut.js
index cceab15..98dd74f 100644
--- a/modules/walnut.js
+++ b/modules/walnut.js
@@ -34,6 +34,12 @@ function assert_null (got) {
     return true;
 }
 
+function assert_undefined (got) {
+    if (got !== undefined)
+        throw new Error("expected undefined, got <"+got+">.");
+    return true;
+}
+
 function assert_not (got) {
     if (got)
         throw new Error("expected a false value, got <"+got+">.");
diff --git a/tests/simple/browser-object-precedence.js 
b/tests/simple/browser-object-precedence.js
new file mode 100644
index 0000000..c8d0320
--- /dev/null
+++ b/tests/simple/browser-object-precedence.js
@@ -0,0 +1,52 @@
+require('walnut.js');
+require('element.js');
+require('keywords.js');
+
+{
+  define_keywords("$command", "$page_mode", "$interactive", "$binding");
+  let test = function(expect) {
+      keywords(arguments);
+      var I = {
+          browser_object: arguments.$interactive,
+          binding_browser_object: arguments.$binding,
+          buffer: { default_browser_object_classes: {
+              test: arguments.$page_mode } },
+          command: { name: "test", browser_object: arguments.$command },
+      };
+      var result = get_browser_object(I);
+      if (expect === null)
+          assert_null(result);
+      else if (expect === undefined)
+          assert_undefined(result);
+      else
+          assert_equals(result, expect);
+  }
+
+  let suite = {
+      test_get_browser_object_none: function () {
+          test(null, $command = null);
+          test(undefined);
+      },
+      test_get_browser_object_interactive: function () {
+          test("i", $interactive = "i", $command = browser_object_links);
+          test("i", $interactive = "i", $page_mode = "p");
+          test("i", $interactive = "i", $binding = "b");
+      },
+      test_get_browser_object_binding: function () {
+          test("b", $binding = "b", $command = browser_object_links);
+          test("b", $binding = "b", $command = "c");
+          test("b", $binding = "b", $page_mode = "p");
+      },
+      test_get_browser_object_page_mode: function () {
+          test("p", $page_mode = "p", $command = browser_object_links);
+      },
+      test_get_browser_object_command: function () {
+          test(browser_object_links, $command = browser_object_links);
+          test("c", $command = "c", $page_mode = "p");
+          test("c", $command = "c", $interactive = "i");
+          // Strange case:
+          test("i", $command = "c", $interactive = "i", $binding = "b");
+      },
+  };
+  walnut_run(suite);
+}
-- 
1.7.7

_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to