Gilles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/156753

Change subject: Change image load check strategy
......................................................................

Change image load check strategy

Using the "complete" property worked for the file page, but not
for media viewer because change the src of an img doesn't reset
the prop.

This introduces a custom event that cucumber can listen to in order
to know when the full resolution image had been loaded in media
viewer.

Change-Id: I40875166e70badbb35106c4a3536c706a7c815b4
---
M resources/mmv/mmv.js
M tests/browser/features/mmv_performance.feature
M tests/browser/features/step_definitions/mmv_performance_steps.rb
3 files changed, 31 insertions(+), 21 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer 
refs/changes/53/156753/1

diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js
index cf1c6de..4b47378 100644
--- a/resources/mmv/mmv.js
+++ b/resources/mmv/mmv.js
@@ -409,6 +409,8 @@
                        this.ui.canvas.unblur();
                }
 
+               $( document ).trigger( $.Event( 'mmv-fullres-loaded') );
+
                mw.mmv.actionLogger.log( 'image-view' );
        };
 
diff --git a/tests/browser/features/mmv_performance.feature 
b/tests/browser/features/mmv_performance.feature
index dd14cef..e37734e 100644
--- a/tests/browser/features/mmv_performance.feature
+++ b/tests/browser/features/mmv_performance.feature
@@ -14,11 +14,13 @@
     Given I have a small browser window
     When I click on an unrelated image in the article to warm up the browser 
cache
     When I close MMV
+    When I listen to the mediaviewer image load
     When I click on the first image in the article
     Then the MMV image is loaded in 125 percent of the time with a warm cache 
and an average browser window
 
   Scenario: MMV with cold cache and average browser window
     Given I have an average browser window
+    When I listen to the mediaviewer image load
     When I click on the first image in the article
     Then the MMV image is loaded in 210 percent of the time with a cold cache 
and an average browser window
 
@@ -26,11 +28,13 @@
     Given I have an average browser window
     When I click on an unrelated image in the article to warm up the browser 
cache
     When I close MMV
+    When I listen to the mediaviewer image load
     When I click on the first image in the article
     Then the MMV image is loaded in 125 percent of the time with a warm cache 
and an average browser window
 
   Scenario: MMV with cold cache and large browser window
     Given I have a large browser window
+    When I listen to the mediaviewer image load
     When I click on the first image in the article
     Then the MMV image is loaded in 240 percent of the time with a cold cache 
and a large browser window
 
@@ -38,5 +42,6 @@
     Given I have a large browser window
     When I click on an unrelated image in the article to warm up the browser 
cache
     When I close MMV
+    When I listen to the mediaviewer image load
     When I click on the first image in the article
     Then the MMV image is loaded in 125 percent of the time with a warm cache 
and a large browser window
\ No newline at end of file
diff --git a/tests/browser/features/step_definitions/mmv_performance_steps.rb 
b/tests/browser/features/step_definitions/mmv_performance_steps.rb
index cfeda94..3ad6cf0 100644
--- a/tests/browser/features/step_definitions/mmv_performance_steps.rb
+++ b/tests/browser/features/step_definitions/mmv_performance_steps.rb
@@ -23,9 +23,31 @@
   @browser = browser(test_name(@scenario), {user_agent: 
ENV["BROWSER_USERAGENT"]})
 end
 
+When /^I listen to the mediaviewer image load$/ do
+  @browser.execute_script("
+    $( document ).on( 'mmv-fullres-loaded', function() {
+      $( 'body' ).append( '<div class=\"mw-mmv-image-loaded-cucumber\"/>' );
+    } );
+  ")
+end
+
 Then /^the File: page image is loaded$/ do
   on(CommonsPage) do |page|
-    wait_for_image_load page, ".fullImageLink img"
+    @browser.execute_script("
+    function wait_for_image() {
+            var $img = $( '.fullImageLink img' );
+            if ( $img.length
+                && $img.attr( 'src' ).match(/Kerala/)
+                && $img.prop( 'complete' ) ) {
+                $( 'body' ).append( '<div 
class=\"mw-mmv-image-loaded-cucumber\"/>' );
+            } else {
+                setTimeout( wait_for_image, 10 );
+            }
+        }
+        wait_for_image();
+    ")
+
+    Watir::Wait.until { page.mmv_image_loaded_cucumber_element.exists? }
     #Has to be a global variable, otherwise it doesn't survive between 
scenarios
     $commons_time = Time.now.getutc - @commons_open_time
     log_performance "file-page", ( $commons_time * 1000 ).to_i.to_s, "", ""
@@ -34,32 +56,13 @@
 
 Then /^the MMV image is loaded in (\d+) percent of the time with a (.*) cache 
and an? (.*) browser window$/ do |percentage, cache, window_size|
   on(E2ETestPage) do |page|
-    wait_for_image_load page, ".mw-mmv-image img"
+    Watir::Wait.until { page.mmv_image_loaded_cucumber_element.exists? }
     mmv_time = Time.now.getutc - @image_click_time
     log_performance "mmv", (mmv_time * 1000).to_i.to_s, cache, window_size
 
     expected_time = $commons_time * ( percentage.to_f / 100.0 )
     mmv_time.should < expected_time
   end
-end
-
-def wait_for_image_load ( page, css_class )
-  @browser.execute_script("
-      function wait_for_image() {
-          var $img = $( '" + css_class + "' );
-          if ( $img.length
-              && $img.attr( 'src' ).match(/Kerala/)
-              && !$img.attr( 'src' ).match(/\\/220px-/) // Blurry placeholder
-              && $img.prop( 'complete' ) ) {
-              $( 'body' ).append( '<div 
class=\"mw-mmv-image-loaded-cucumber\"/>' );
-          } else {
-              setTimeout( wait_for_image, 10 );
-          }
-      }
-      wait_for_image();
-  ")
-
-  Watir::Wait.until { page.mmv_image_loaded_cucumber_element.exists? }
 end
 
 def log_performance ( type, duration, cache, window_size )

-- 
To view, visit https://gerrit.wikimedia.org/r/156753
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I40875166e70badbb35106c4a3536c706a7c815b4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to