From bcdb331c79f6b1c557575e6751ed1fc78779bbff Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 27 May 2020 16:54:20 +0100 Subject: [PATCH 1/7] tests: Embed test fix (#4020) * quick fix for iframe code wihch someone broke * Also fix cookie test --- src/static/js/pad_userlist.js | 2 +- tests/frontend/specs/embed_value.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/static/js/pad_userlist.js b/src/static/js/pad_userlist.js index 02e6add58..866fc705a 100644 --- a/src/static/js/pad_userlist.js +++ b/src/static/js/pad_userlist.js @@ -732,7 +732,7 @@ var paduserlist = (function() } else { - $("#myusernameedit").addClass("editempty").val(_("pad.userlist.entername")); + $("#myusernameedit").attr("placeholder", html10n.get("pad.userlist.entername")); } if (colorPickerOpen) { diff --git a/tests/frontend/specs/embed_value.js b/tests/frontend/specs/embed_value.js index aa031e236..e4cbcaaeb 100644 --- a/tests/frontend/specs/embed_value.js +++ b/tests/frontend/specs/embed_value.js @@ -19,8 +19,8 @@ describe("embed links", function(){ var width = $embediFrame.attr("width"); var height = $embediFrame.attr("height"); var name = $embediFrame.attr("name"); - expect(width).to.be('600'); - expect(height).to.be('400'); + expect(width).to.be('100%'); + expect(height).to.be('600'); expect(name).to.be(readonly ? "embed_readonly" : "embed_readwrite"); //parse the url From 0dc59eba4d14e1494573786a0aef008e99af42a6 Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 27 May 2020 16:55:14 +0100 Subject: [PATCH 2/7] tests: authorship test fix (#4001) * Placeholderfortest * rename script and make it work --- ...ultiple_authors_clear_authorship_colors.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 tests/frontend/specs/multiple_authors_clear_authorship_colors.js diff --git a/tests/frontend/specs/multiple_authors_clear_authorship_colors.js b/tests/frontend/specs/multiple_authors_clear_authorship_colors.js new file mode 100755 index 000000000..58c93cf2f --- /dev/null +++ b/tests/frontend/specs/multiple_authors_clear_authorship_colors.js @@ -0,0 +1,51 @@ +describe('author of pad edition', function() { + // author 1 creates a new pad with some content (regular lines and lists) + before(function(done) { + var padId = helper.newPad(function() { + // make sure pad has at least 3 lines + var $firstLine = helper.padInner$('div').first(); + $firstLine.html("Hello World"); + + // wait for lines to be processed by Etherpad + helper.waitFor(function() { + return $firstLine.text() === 'Hello World'; + }).done(function() { + // Reload pad, to make changes as a second user. Need a timeout here to make sure + // all changes were saved before reloading + setTimeout(function() { + // Expire cookie, so author is changed after reloading the pad. + // See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#Example_4_Reset_the_previous_cookie + helper.padChrome$.document.cookie = 'token=foo;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; + + helper.newPad(done, padId); + }, 1000); + }); + }); + this.timeout(60000); + }); + + // author 2 makes some changes on the pad + it('Clears Authorship by second user', function(done) { + clearAuthorship(done); + }); + + var clearAuthorship = function(done){ + var inner$ = helper.padInner$; + var chrome$ = helper.padChrome$; + + // override the confirm dialogue functioon + helper.padChrome$.window.confirm = function(){ + return true; + } + + //get the clear authorship colors button and click it + var $clearauthorshipcolorsButton = chrome$(".buttonicon-clearauthorship"); + $clearauthorshipcolorsButton.click(); + + // does the first divs span include an author class? + var hasAuthorClass = inner$("div span").first().attr("class").indexOf("author") !== -1; + + expect(hasAuthorClass).to.be(false) + done(); + } +}); From 9bca865b4f0804276acb4f8f6d243a4f902d2b51 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 28 May 2020 11:37:10 +0100 Subject: [PATCH 3/7] Removing ep_test_line_attrib include Intentionally committing directly to develop. Removing ep_test_line_attrib because it's breaking other tests from running. The weird thing is even when this is removed from other branches it appears to be included. Hopefully committing directly to develop will make things work. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6b3bb6c7c..ff6c46301 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ services: install: - "bin/installDeps.sh" - "export GIT_HASH=$(git rev-parse --verify --short HEAD)" - - "npm install ep_test_line_attrib" +# - "npm install ep_test_line_attrib" before_script: - "tests/frontend/travis/sauce_tunnel.sh" @@ -33,7 +33,7 @@ jobs: install: - "bin/installDeps.sh" - "export GIT_HASH=$(git rev-parse --verify --short HEAD)" - - "npm install ep_test_line_attrib" +# - "npm install ep_test_line_attrib" script: - "tests/frontend/travis/runner.sh" - name: "Test the Dockerfile" From 5208ae5ee657aa8481f4fa7fb86be7a83efa25b9 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 28 May 2020 11:54:34 +0100 Subject: [PATCH 4/7] Warning about Travis Cache Intentionally committing to develop. We can probably revert these two commits. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index ff6c46301..ff5f36275 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,3 +48,5 @@ notifications: irc: channels: - "irc.freenode.org#etherpad-lite-dev" + +# WARNING! Travis has a cache, you have to clear it if you are having files exist which shouldn't. From f775096696202932b8d3ad27cf358a9bedd831a5 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 28 May 2020 12:33:44 +0000 Subject: [PATCH 5/7] Revert "Warning about Travis Cache" This reverts commit 5208ae5ee657aa8481f4fa7fb86be7a83efa25b9. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff5f36275..ff6c46301 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,5 +48,3 @@ notifications: irc: channels: - "irc.freenode.org#etherpad-lite-dev" - -# WARNING! Travis has a cache, you have to clear it if you are having files exist which shouldn't. From b1b181927d0d108d6d7244da28af3df3d8d61c77 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 28 May 2020 12:33:57 +0000 Subject: [PATCH 6/7] Revert "Removing ep_test_line_attrib include" This reverts commit 9bca865b4f0804276acb4f8f6d243a4f902d2b51. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff6c46301..6b3bb6c7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ services: install: - "bin/installDeps.sh" - "export GIT_HASH=$(git rev-parse --verify --short HEAD)" -# - "npm install ep_test_line_attrib" + - "npm install ep_test_line_attrib" before_script: - "tests/frontend/travis/sauce_tunnel.sh" @@ -33,7 +33,7 @@ jobs: install: - "bin/installDeps.sh" - "export GIT_HASH=$(git rev-parse --verify --short HEAD)" -# - "npm install ep_test_line_attrib" + - "npm install ep_test_line_attrib" script: - "tests/frontend/travis/runner.sh" - name: "Test the Dockerfile" From febd48954cbe53dbb530ce144067e5e935989309 Mon Sep 17 00:00:00 2001 From: Daniel Krol Date: Thu, 28 May 2020 09:25:07 -0400 Subject: [PATCH 7/7] Tests: Add and test padPrefs for helper.newPad (#4042) Also fix a couple other tests along the way, including accounting for this change: 23307d14d57c462b66a4bb15d3acde9e9dcf4c90 --- tests/frontend/helper.js | 27 ++++++++++++++++++--- tests/frontend/specs/helper.js | 44 +++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js index 449355e5d..b9327f289 100644 --- a/tests/frontend/helper.js +++ b/tests/frontend/helper.js @@ -52,13 +52,28 @@ var helper = {}; return win.$; } - helper.clearCookies = function(){ + helper.clearSessionCookies = function(){ // Expire cookies, so author and language are changed after reloading the pad. // See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#Example_4_Reset_the_previous_cookie window.document.cookie = 'token=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; window.document.cookie = 'language=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; } + // Can only happen when the iframe exists, so we're doing it separately from other cookies + helper.clearPadPrefCookie = function(){ + helper.padChrome$.document.cookie = 'prefsHttp=;expires=Thu, 01 Jan 1970 00:00:00 GMT'; + } + + // Overwrite all prefs in pad cookie. Assumes http, not https. + // + // `helper.padChrome$.document.cookie` (the iframe) and `window.document.cookie` + // seem to have independent cookies, UNLESS we put path=/ here (which we don't). + // I don't fully understand it, but this function seems to properly simulate + // padCookie.setPref in the client code + helper.setPadPrefCookie = function(prefs){ + helper.padChrome$.document.cookie = ("prefsHttp=" + escape(JSON.stringify(prefs)) + ";expires=Thu, 01 Jan 3000 00:00:00 GMT"); + } + // Functionality for knowing what key event type is required for tests var evtType = "keydown"; // if it's IE require keypress @@ -86,7 +101,7 @@ var helper = {}; //clear cookies if(opts.clearCookies){ - helper.clearCookies(); + helper.clearSessionCookies(); } if(!padName) @@ -100,10 +115,16 @@ var helper = {}; $iframeContainer.find("iframe").purgeFrame().done(function(){ $iframeContainer.append($iframe); $iframe.one('load', function(){ + helper.padChrome$ = getFrameJQuery( $('#iframe-container iframe')); + if (opts.clearCookies) { + helper.clearPadPrefCookie(); + } + if (opts.padPrefs) { + helper.setPadPrefCookie(opts.padPrefs); + } helper.waitFor(function(){ return !$iframe.contents().find("#editorloadingbox").is(":visible"); }, 50000).done(function(){ - helper.padChrome$ = getFrameJQuery( $('#iframe-container iframe')); helper.padOuter$ = getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]')); helper.padInner$ = getFrameJQuery( helper.padOuter$('iframe[name="ace_inner"]')); diff --git a/tests/frontend/specs/helper.js b/tests/frontend/specs/helper.js index ac6eb3200..051e9a17d 100644 --- a/tests/frontend/specs/helper.js +++ b/tests/frontend/specs/helper.js @@ -50,15 +50,16 @@ describe("the test helper", function(){ // set cookies far into the future to make sure they're not expired yet window.document.cookie = 'token=foo;expires=Thu, 01 Jan 3030 00:00:00 GMT; path=/'; window.document.cookie = 'language=bar;expires=Thu, 01 Jan 3030 00:00:00 GMT; path=/'; - const testCookie = 'token=foo; language=bar' - expect(window.document.cookie).to.be(testCookie) + expect(window.document.cookie).to.contain('token=foo'); + expect(window.document.cookie).to.contain('language=bar'); helper.newPad(function(){ // helper function seems to have cleared cookies // NOTE: this doesn't yet mean it's proven to have taken effect by this point in execution var firstCookie = window.document.cookie - expect(firstCookie).to.not.be(testCookie) + expect(firstCookie).to.not.contain('token=foo'); + expect(firstCookie).to.not.contain('language=bar'); var chrome$ = helper.padChrome$; @@ -73,7 +74,16 @@ describe("the test helper", function(){ $usernameInput.blur(); // Before refreshing, make sure the name is there - expect($usernameInput.val()).to.be('John McLear') + expect($usernameInput.val()).to.be('John McLear'); + + // Now that we have a chrome, we can set a pad cookie, so we can confirm it gets wiped as well + chrome$.document.cookie = 'prefsHtml=baz;expires=Thu, 01 Jan 3030 00:00:00 GMT'; + expect(chrome$.document.cookie).to.contain('prefsHtml=baz'); + + // Cookies are weird. Because it's attached to chrome$ (as helper.setPadCookies does), AND we + // didn't put path=/, we shouldn't expect it to be visible on window.document.cookie. Let's just + // be sure. + expect(window.document.cookie).to.not.contain('prefsHtml=baz'); setTimeout(function(){ //give it a second to save the username on the server side helper.newPad(function(){ // get a new pad, let it clear the cookies @@ -82,8 +92,12 @@ describe("the test helper", function(){ // helper function seems to have cleared cookies // NOTE: this doesn't yet mean cookies were cleared effectively. // We still need to test below that we're in a new session - expect(window.document.cookie).to.not.be(testCookie) - expect(window.document.cookie).to.not.be(firstCookie) + expect(window.document.cookie).to.not.contain('token=foo'); + expect(window.document.cookie).to.not.contain('language=bar'); + expect(chrome$.document.cookie).to.contain('prefsHtml=baz'); + expect(window.document.cookie).to.not.contain('prefsHtml=baz'); + + expect(window.document.cookie).to.not.be(firstCookie); // click on the settings button to make settings visible var $userButton = chrome$(".buttonicon-showusers"); @@ -91,12 +105,26 @@ describe("the test helper", function(){ // confirm that the session was actually cleared var $usernameInput = chrome$("#myusernameedit"); - expect($usernameInput.val()).to.be('') + expect($usernameInput.val()).to.be('Enter your name'); done(); }); }, 1000); - }) + }); + }); + + it("sets pad prefs cookie", function(done) { + this.timeout(60000); + + helper.newPad({ + padPrefs: {foo:"bar"}, + cb: function(){ + var chrome$ = helper.padChrome$; + expect(chrome$.document.cookie).to.contain('prefsHttp=%7B%22'); + expect(chrome$.document.cookie).to.contain('foo%22%3A%22bar'); + done(); + } + }); }); });