Skip to content

Commit

Permalink
Fix popup not being in proper state for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed Oct 18, 2017
1 parent 68231f6 commit 243eb75
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,8 @@ function refreshPopup(tabId) {
// or a page that loaded everything before our most recent initialization
if (!badger.tabData.hasOwnProperty(tabId)) {
// replace inapplicable summary text with a Badger logo
$('#pbInstructions').html(
"<img src='" +
chrome.extension.getURL('icons/badger-128.png') +
"' alt=''>"
).css({
"text-align": "center"
});
$('#blockedResourcesContainer').hide();
$('#big-badger-logo').show();

// hide inapplicable buttons
$('#deactivate_site_btn').hide();
Expand All @@ -273,6 +268,14 @@ function refreshPopup(tabId) {
$('.tooltip').tooltipster();

return;

} else {
// revert any hiding/showing above for cases when refreshPopup gets called
// more than once for the same popup, such as during functional testing
$('#blockedResourcesContainer').show();
$('#big-badger-logo').hide();
$('#deactivate_site_btn').show();
$('#error').show();
}

let origins = badger.getAllOriginsForTab(tabId);
Expand Down
5 changes: 5 additions & 0 deletions src/skin/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,17 @@ <h1 id="report_title" class="i18n_report_title"></h1>
<div class='clear'></div>
<div id="subtitle"><span id="version" class="i18n_version"></span></div>
</div>

<div id="blockedResourcesContainer">
<p id="pbInstructions"> <span class="i18n_pb_detected"></span> <span id='number_trackers'></span> <span class="i18n_popup_instructions"></span></p>
<div class="spacer"></div>
<div id="blockedResources"><span class="options_loading"></span></div>
</div>

<div id="big-badger-logo" style="display:none; text-align:center; margin:18px 0;">
<img src="/icons/badger-128.png" alt="">
</div>

<div id="siteControls">
<button id="deactivate_site_btn" class="pbButton"><span class="i18n_popup_disable_for_site"></span></button>
<button id="activate_site_btn" class="pbButton" style="display:none"> <span class="i18n_popup_enable_for_site"></span></button>
Expand Down
19 changes: 19 additions & 0 deletions tests/selenium/popup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ def switch_to_new_window(self, handles_before, max_retries=5):
def open_popup(self, close_overlay=True):
"""Open popup and optionally close overlay."""
self.load_url(self.popup_url, wait_on_site=1)

# hack to get tabData populated for the popup's tab
# to get the popup shown for regular pages
# as opposed to special (no-tabData) browser pages
# TODO instead use a proper popup-opening function to open the popup
# for some test page like https://www.eff.org/files/badgertest.txt;
# for example, see https://github.com/EFForg/privacybadger/issues/1634
self.js("""getTab(function (tab) {
badger.recordFrame(tab.id, 0, -1, tab.url);
refreshPopup(tab.id);
window.DONE_REFRESHING = true;
});""")
# wait until the async getTab function is done
self.wait_for_script(
"return typeof window.DONE_REFRESHING != 'undefined'",
timeout=5,
message="Timed out waiting for getTab() to complete."
)

if close_overlay:
# Click 'X' element to close overlay.
try:
Expand Down

0 comments on commit 243eb75

Please sign in to comment.