Skip to content

Commit

Permalink
Minor DRY in storage clearance calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jul 26, 2019
1 parent 9c61fd4 commit 23b9fdd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions lib/capybara/selenium/driver_specializations/chrome_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ def storage_types_to_clear
end

def clear_all_storage?
options.values_at(:clear_session_storage, :clear_local_storage).none? { |s| s == false }
storage_clears.none? { |s| s == false }
end

def uniform_storage_clear?
clear = options.values_at(:clear_session_storage, :clear_local_storage)
clear.all? { |s| s == false } || clear.none? { |s| s == false }
storage_clears.uniq { |s| s == false }.length <= 1
end

def storage_clears
options.values_at(:clear_session_storage, :clear_local_storage)
end

def clear_storage
Expand Down
12 changes: 7 additions & 5 deletions lib/capybara/selenium/driver_specializations/edge_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ def storage_types_to_clear
end

def clear_all_storage?
options.values_at(:clear_session_storage, :clear_local_storage).none? { |s| s == false }
storage_clears.none? { |s| s == false }
end

def uniform_storage_clear?
clear = options.values_at(:clear_session_storage, :clear_local_storage)
clear.all? { |s| s == false } || clear.none? { |s| s == false }
storage_clears.uniq { |s| s == false }.length <= 1
end

def storage_clears
options.values_at(:clear_session_storage, :clear_local_storage)
end

def clear_storage
# Chrome errors if attempt to clear storage on about:blank
# In W3C mode it crashes chromedriver
# Edgedriver crashes if attempt to clear storage on about:blank
url = current_url
super unless url.nil? || url.start_with?('about:')
end
Expand Down

0 comments on commit 23b9fdd

Please sign in to comment.