Skip to content

Commit

Permalink
make notification bar password tests run faster
Browse files Browse the repository at this point in the history
  • Loading branch information
diracdeltas committed Mar 11, 2017
1 parent 56537e5 commit 51d2d58
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
54 changes: 36 additions & 18 deletions test/components/notificationBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Brave = require('../lib/brave')
const {notificationBar, titleBar, urlInput} = require('../lib/selectors')

describe('notificationBar', function () {
describe('notificationBar permissions', function () {
function * setup (client) {
yield client
.waitForBrowserWindow()
Expand All @@ -14,12 +14,6 @@ describe('notificationBar', function () {
Brave.beforeAll(this)
before(function * () {
this.notificationUrl = Brave.server.url('notification.html')
this.loginUrl1 = Brave.server.url('login1.html')
this.loginUrl2 = Brave.server.url('login2.html')
this.loginUrl3 = Brave.server.url('login3.html')
this.loginUrl4 = Brave.server.url('login4.html')
this.loginUrl5 = Brave.server.url('login5.html')
this.loginUrl6 = Brave.server.url('login6.html')
yield setup(this.app.client)
})

Expand Down Expand Up @@ -94,22 +88,49 @@ describe('notificationBar', function () {
return this.getText(titleBar).then((val) => val.includes('granted'))
})
})
})

describe('notificationBar passwords', function () {
function * setup (client) {
yield client
.waitForBrowserWindow()
.waitForVisible(urlInput)
}

Brave.beforeAll(this)

beforeEach(function * () {
yield this.app.client
.waitForElementCount('.notificationItem', 0)
})

before(function * () {
this.loginUrl1 = Brave.server.url('login1.html')
this.loginUrl2 = Brave.server.url('login2.html')
this.loginUrl3 = Brave.server.url('login3.html')
this.loginUrl4 = Brave.server.url('login4.html')
this.loginUrl5 = Brave.server.url('login5.html')
this.loginUrl6 = Brave.server.url('login6.html')
yield setup(this.app.client)
})

it('shows notification for login form', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.loginUrl1)
.url(this.loginUrl1)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
return this.getText(notificationBar).then((val) => val.includes('localhost') && val.includes('brave_user'))
return this.getText(notificationBar).then((val) => {
return val.includes('localhost') && val.includes('brave_user')
})
}).click('button=No')
})

it('does not include a password in the notification bar', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.loginUrl6)
.url(this.loginUrl6)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
Expand All @@ -122,7 +143,7 @@ describe('notificationBar', function () {
it('autofills remembered password on login form', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.loginUrl1)
.url(this.loginUrl1)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
Expand All @@ -133,7 +154,7 @@ describe('notificationBar', function () {
.waitForExist('[data-test-id="passwordItem"]')
.windowByUrl(Brave.browserWindowUrl)
.tabByIndex(0)
.loadUrl(this.loginUrl4)
.url(this.loginUrl4)
.waitUntil(function () {
return this.getValue('#user').then((val) => val === 'brave_user') &&
this.getValue('#password').then((val) => val === 'testing') &&
Expand All @@ -145,10 +166,7 @@ describe('notificationBar', function () {
it('autofills remembered password on login page with multiple forms', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.loginUrl1)
.windowByUrl(Brave.browserWindowUrl)
.tabByIndex(0)
.loadUrl(this.loginUrl5)
.url(this.loginUrl5)
.waitUntil(function () {
return this.getValue('#user').then((val) => val === 'brave_user') &&
this.getValue('#password').then((val) => val === 'testing') &&
Expand All @@ -160,15 +178,15 @@ describe('notificationBar', function () {
it('does not show login form notification if user turns it off for the site', function * () {
yield this.app.client
.tabByIndex(0)
.loadUrl(this.loginUrl3)
.url(this.loginUrl3)
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(notificationBar)
.waitUntil(function () {
return this.getText(notificationBar).then((val) => val.includes('localhost') && val.includes('brave_user'))
})
.click('button=Never for this site')
.tabByIndex(0)
.loadUrl(this.loginUrl2)
.url(this.loginUrl2)
.windowByUrl(Brave.browserWindowUrl)
.isExisting(notificationBar).should.eventually.be.false
})
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/login1.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
document.querySelector('#password').value = 'testing'
document.querySelector('#submit').click()
}
}, 1000)
}, 200)
</script>
</head>
<body>
<div id="content" class="login">
<h1>Login</h1>
<form method="post" id="acctmgr_loginform" action="/"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" id="acctmgr_loginform" action="login4.html"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div>
<input type="hidden" name="referer" value="bar" />
</div>
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/login2.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
document.querySelector('#password').value = 'testing'
document.querySelector('#submit').click()
}
}, 1000)
}, 200)
</script>
</head>
<body>
<div id="content" class="login">
<h1>Login</h1>
<form method="post" id="acctmgr_loginform" action=""><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" id="acctmgr_loginform" action="login4.html"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div>
<input type="hidden" name="referer" value="bar" />
</div>
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/login3.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
document.querySelector('#password').value = 'testing'
document.querySelector('#submit').click()
}
}, 1000)
}, 200)
</script>
</head>
<body>
<div id="content" class="login">
<h1>Login</h1>
<form method="post" id="acctmgr_loginform" action=""><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" id="acctmgr_loginform" action="login5.html"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div>
<input type="hidden" name="referer" value="bar" />
</div>
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/login4.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body>
<div id="content" class="login">
<h1>Login</h1>
<form method="post" id="acctmgr_loginform" action="/"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" id="acctmgr_loginform" action="login4.html"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div>
<input type="hidden" name="referer" value="bar" />
</div>
Expand All @@ -25,7 +25,7 @@ <h1>Login</h1>
</div>
<div id="content2" class="login">
<h1>Login 2</h1>
<form method="post" action="/blah"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" action="https://brave.com/"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div class="textbox">
<label for="user">Username:</label><br />
<input type="text" name="user" id='user2' class="textwidget" />
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/login5.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body>
<div id="content1" class="login">
<h1>Login 1</h1>
<form method="post" action="/"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" action="login4.html"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div class="textbox">
<label for="user">Username:</label><br />
<input type="text" id="user" name="user" class="textwidget" />
Expand All @@ -22,7 +22,7 @@ <h1>Login 1</h1>
</div>
<div id="content2" class="login">
<h1>Login 2</h1>
<form method="post" action="/"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<form method="post" action="login4.html"><div><input type="hidden" name="__FORM_TOKEN" value="foo" /></div>
<div class="textbox">
<label for="user">Username:</label><br />
<input type="text" name="user" id='user2' class="textwidget" />
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/login6.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
}, 200)
</script>
<form action="/blah" name="ChangePassForm" id="ChangePassForm">
<form action="/login4.html" name="ChangePassForm" id="ChangePassForm">
<input type="hidden" id="countryId" name="countryId" value="1" />
<input type="hidden" name="MfcISAPICommand" value="HandleNewPassword">
<input type="hidden" name="srt" value="01"><div class="rclSir"></div>
Expand Down

0 comments on commit 51d2d58

Please sign in to comment.