Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/browser/snippets.js

Issue 29995559: Issue 7236 - Handle sub properties in abort-on-property snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Formatting Created March 19, 2019, 5:24 p.m.
Right Patch Set: tweak property names Created March 20, 2019, 4:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/browser/elemHideEmulation.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 25 matching lines...) Expand all
36 snippet(...args); 36 snippet(...args);
37 37
38 // For snippets that run in the context of the document via a <script> 38 // For snippets that run in the context of the document via a <script>
39 // element (i.e. snippets that use makeInjector()), we need to wait for 39 // element (i.e. snippets that use makeInjector()), we need to wait for
40 // execution to be complete. 40 // execution to be complete.
41 await timeout(100); 41 await timeout(100);
42 } 42 }
43 43
44 exports.testAbortOnPropertyReadSnippet = async function(test) 44 exports.testAbortOnPropertyReadSnippet = async function(test)
45 { 45 {
46 window.abpTest = "foo"; 46 function testProperty(property, result = true, errorName = "ReferenceError")
47
48 function testProperty(property, result = true)
49 { 47 {
50 let path = property.split("."); 48 let path = property.split(".");
51 49
52 let exceptionCaught = false; 50 let exceptionCaught = false;
53 let value = 1; 51 let value = 1;
54 52
55 try 53 try
56 { 54 {
57 let obj = window; 55 let obj = window;
58 while (path.length > 1) 56 while (path.length > 1)
59 obj = obj[path.shift()]; 57 obj = obj[path.shift()];
60 value = obj[path.shift()]; 58 value = obj[path.shift()];
61 } 59 }
62 catch (e) 60 catch (e)
63 { 61 {
62 test.equal(e.name, errorName);
64 exceptionCaught = true; 63 exceptionCaught = true;
65 } 64 }
66 65
67 test.equal( 66 test.equal(
68 exceptionCaught, 67 exceptionCaught,
69 result, 68 result,
70 `The property "${property}" ${result ? "should" : "shouldn't"} trigger an exception.` 69 `The property "${property}" ${result ? "should" : "shouldn't"} trigger an exception.`
71 ); 70 );
72 test.equal( 71 test.equal(
73 value, 72 value,
74 result ? 1 : undefined, 73 result ? 1 : undefined,
75 `The value for "${property}" ${result ? "shouldn't" : "should"} have been read.` 74 `The value for "${property}" ${result ? "shouldn't" : "should"} have been read.`
76 ); 75 );
77 } 76 }
78 77
78 window.abpTest = "fortytwo";
79 await runSnippet(test, "abort-on-property-read", "abpTest"); 79 await runSnippet(test, "abort-on-property-read", "abpTest");
80 testProperty("abpTest"); 80 testProperty("abpTest");
81 81
82 window.abpTest2 = {prop1: "foo"}; 82 window.abpTest2 = {prop1: "fortytwo"};
83
84 await runSnippet(test, "abort-on-property-read", "abpTest2.prop1"); 83 await runSnippet(test, "abort-on-property-read", "abpTest2.prop1");
85 testProperty("abpTest2.prop1"); 84 testProperty("abpTest2.prop1");
86 85
87 // Test that we try to catch a property that don't exist yet. 86 // Test that we try to catch a property that doesn't exist yet.
88 await runSnippet(test, "abort-on-property-read", "abpTest3.prop1"); 87 await runSnippet(test, "abort-on-property-read", "abpTest3.prop1");
89 window.abpTest3 = {prop1: "foo"}; 88 window.abpTest3 = {prop1: "fortytwo"};
90 testProperty("abpTest3.prop1"); 89 testProperty("abpTest3.prop1");
91 90
92 // Test that other properties don't trigger. 91 // Test that other properties don't trigger.
93 testProperty("abpTest3.prop2", false); 92 testProperty("abpTest3.prop2", false);
94 93
95 // Test overwriting the object with another object 94 // Test overwriting the object with another object.
96 window.foo = {bar: {}}; 95 window.abpTest4 = {prop3: {}};
97 await runSnippet(test, "abort-on-property-read", "foo.bar.lambda"); 96 await runSnippet(test, "abort-on-property-read", "abpTest4.prop3.foo");
98 testProperty("foo.bar.lambda"); 97 testProperty("abpTest4.prop3.foo");
99 window.foo.bar = {}; 98 window.abpTest4.prop3 = {};
100 testProperty("foo.bar.lambda"); 99 testProperty("abpTest4.prop3.foo");
101 100
102 // Test if we start with a non-object 101 // Test if we start with a non-object.
103 window.foo2 = 5; 102 window.abpTest5 = 42;
104 await runSnippet(test, "abort-on-property-read", "foo2.bar2.lambda"); 103 await runSnippet(test, "abort-on-property-read", "abpTest5.prop4.bar");
105 testProperty("foo2.bar2.lambda"); 104
106 window.foo2 = {}; 105 testProperty("abpTest5.prop4.bar", true, "TypeError");
107 testProperty("foo2.bar2.lambda"); 106
107 window.abpTest5 = {prop4: 42};
108 testProperty("abpTest5.prop4.bar", false);
109 window.abpTest5 = {prop4: {}};
110 testProperty("abpTest5.prop4.bar");
108 111
109 test.done(); 112 test.done();
110 }; 113 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld