[MediaWiki-commits] [Gerrit] Browser test for chunked uploads - change (mediawiki...UploadWizard)

2015-03-02 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Browser test for chunked uploads
..


Browser test for chunked uploads

Bug: T89289
Change-Id: Id5ecf50a09a9f5032253c7a9c6a78cebfb7a264c
---
A tests/browser/features/chunked_upload.feature
A tests/browser/features/step_definitions/chunked_upload_steps.rb
M tests/browser/features/step_definitions/upload_wizard_steps.rb
M tests/browser/features/support/env.rb
A tests/browser/features/support/file_helper.rb
M tests/browser/features/support/pages/upload_page.rb
M tests/browser/features/support/pages/upload_wizard_page.rb
7 files changed, 73 insertions(+), 9 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  Gergő Tisza: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/tests/browser/features/chunked_upload.feature 
b/tests/browser/features/chunked_upload.feature
new file mode 100644
index 000..109243e
--- /dev/null
+++ b/tests/browser/features/chunked_upload.feature
@@ -0,0 +1,9 @@
+@login @chrome @firefox @commons.wikimedia.beta.wmflabs.org 
@test2.wikipedia.org
+Feature: Chunked upload
+
+  Scenario: Upload large file
+Given I am logged in
+  And I am on the file upload step
+  And chunked upload is enabled in my preferences
+When I upload a large file
+Then the upload should finish
diff --git a/tests/browser/features/step_definitions/chunked_upload_steps.rb 
b/tests/browser/features/step_definitions/chunked_upload_steps.rb
new file mode 100644
index 000..0f02a02
--- /dev/null
+++ b/tests/browser/features/step_definitions/chunked_upload_steps.rb
@@ -0,0 +1,22 @@
+Given(/^I am on the file upload step$/) do
+  visit(UploadWizardPage) do |page|
+# if we are on the learn step, move to next step, otherwise do nothing
+if page.stepdiv_file_element.visible? == false
+  step I click the Next button at the Learn page
+end
+  end
+end
+
+And(/^chunked upload is enabled in my preferences$/) do
+  # quite a nasty hack. Faster than actually enabling and reloading, though, 
and does not have race conditions
+  @browser.execute_script('mw.UploadWizard.config.enableChunked = true;')
+end
+
+When(/^I upload a large file$/) do
+  path = create_large_image(11_000_000)
+  on(UploadPage).add_file(path)
+end
+
+Then(/^the upload should finish$/) do
+  on(UploadPage).continue_element.when_present(300).should be_visible
+end
diff --git a/tests/browser/features/step_definitions/upload_wizard_steps.rb 
b/tests/browser/features/step_definitions/upload_wizard_steps.rb
index 0da0029..357be34 100644
--- a/tests/browser/features/step_definitions/upload_wizard_steps.rb
+++ b/tests/browser/features/step_definitions/upload_wizard_steps.rb
@@ -10,14 +10,6 @@
 # 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FUploadWizard/HEAD/CREDITS
 #
 require tempfile
-require chunky_png
-
-def make_temp_image(filename, shade, width, height)
-  path = #{Dir.tmpdir}/#{filename}
-  image = ChunkyPNG::Image.new(shade, width, height)
-  image.save path
-  path
-end
 
 Given(/^I am logged out$/) do
   visit LogoutPage
diff --git a/tests/browser/features/support/env.rb 
b/tests/browser/features/support/env.rb
index 1464413..7254d26 100644
--- a/tests/browser/features/support/env.rb
+++ b/tests/browser/features/support/env.rb
@@ -11,5 +11,9 @@
 #
 require mediawiki_selenium
 
+require_relative file_helper
+
+World(FileHelper)
+
 # This allows us to use wait_for_ajax in step definitions.
 PageObject.javascript_framework = :jquery
diff --git a/tests/browser/features/support/file_helper.rb 
b/tests/browser/features/support/file_helper.rb
new file mode 100644
index 000..fe0b0ca
--- /dev/null
+++ b/tests/browser/features/support/file_helper.rb
@@ -0,0 +1,35 @@
+#
+# This file is subject to the license terms in the COPYING file found in the
+# UploadWizard top-level directory and at
+# 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FUploadWizard/HEAD/COPYING.
 No part of
+# UploadWizard, including this file, may be copied, modified, propagated, or
+# distributed except according to the terms contained in the COPYING file.
+#
+# Copyright 2012-2015 by the Mediawiki developers. See the CREDITS file in the
+# UploadWizard top-level directory and at
+# 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FUploadWizard/HEAD/CREDITS
+#
+require 'tempfile'
+require 'securerandom'
+require 'chunky_png'
+
+# helper functions to generate temporary files for testing image upload
+module FileHelper
+  def make_temp_image(filename, shade, width, height)
+path = #{Dir.tmpdir}/#{filename}
+image = ChunkyPNG::Image.new(shade, width, height)
+image.save path
+path
+  end
+
+  def create_large_image(size)
+path = Tempfile.new(['temp', '.png']).path
+# making the image consist of many triggers might trigger MediaWiki pixel 
limits
+# instead make it 1x1 and pump it up with metadata
+image = 

[MediaWiki-commits] [Gerrit] Browser test for chunked uploads - change (mediawiki...UploadWizard)

2015-02-17 Thread Code Review
Gergő Tisza has uploaded a new change for review.

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

Change subject: Browser test for chunked uploads
..

Browser test for chunked uploads

Bug: T89289
Change-Id: Id5ecf50a09a9f5032253c7a9c6a78cebfb7a264c
---
A tests/browser/features/chunked_upload.feature
A tests/browser/features/step_definitions/chunked_upload_steps.rb
M tests/browser/features/step_definitions/upload_wizard_steps.rb
M tests/browser/features/support/env.rb
A tests/browser/features/support/file_helper.rb
M tests/browser/features/support/pages/upload_wizard_page.rb
6 files changed, 69 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/46/191246/1

diff --git a/tests/browser/features/chunked_upload.feature 
b/tests/browser/features/chunked_upload.feature
new file mode 100644
index 000..a00cf0e
--- /dev/null
+++ b/tests/browser/features/chunked_upload.feature
@@ -0,0 +1,8 @@
+@login @chrome @firefox @commons.wikimedia.beta.wmflabs.org 
@test2.wikipedia.org
+Feature: Chunked upload
+
+  Scenario: Upload large file
+Given I am on the file upload step
+  And chunked upload is enabled in my preferences
+When I upload a large file
+Then the upload should finish
diff --git a/tests/browser/features/step_definitions/chunked_upload_steps.rb 
b/tests/browser/features/step_definitions/chunked_upload_steps.rb
new file mode 100644
index 000..4ee0c2f
--- /dev/null
+++ b/tests/browser/features/step_definitions/chunked_upload_steps.rb
@@ -0,0 +1,17 @@
+Given(/^I am on the file upload step$/) do
+  step I am logged in
+  visit(UploadWizardPage).bypass_learn_step
+end
+
+And(/^chunked upload is enabled in my preferences$/) do
+  on(UploadWizardPage).enable_chunked_uploads
+end
+
+When(/^I upload a large file$/) do
+  path = create_large_file(10)
+  on(UploadPage).add_file(path)
+end
+
+Then(/^the upload should finish$/) do
+  on(UploadPage).continue_element.when_present(15).should be_visible
+end
diff --git a/tests/browser/features/step_definitions/upload_wizard_steps.rb 
b/tests/browser/features/step_definitions/upload_wizard_steps.rb
index 7ef8814..3559da0 100644
--- a/tests/browser/features/step_definitions/upload_wizard_steps.rb
+++ b/tests/browser/features/step_definitions/upload_wizard_steps.rb
@@ -10,14 +10,6 @@
 # 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FUploadWizard/HEAD/CREDITS
 #
 require tempfile
-require chunky_png
-
-def make_temp_image(filename, shade, width, height)
-  path = #{Dir.tmpdir}/#{filename}
-  image = ChunkyPNG::Image.new(shade, width, height)
-  image.save path
-  path
-end
 
 Given(/^I am logged out$/) do
   visit LogoutPage
diff --git a/tests/browser/features/support/env.rb 
b/tests/browser/features/support/env.rb
index 1464413..7254d26 100644
--- a/tests/browser/features/support/env.rb
+++ b/tests/browser/features/support/env.rb
@@ -11,5 +11,9 @@
 #
 require mediawiki_selenium
 
+require_relative file_helper
+
+World(FileHelper)
+
 # This allows us to use wait_for_ajax in step definitions.
 PageObject.javascript_framework = :jquery
diff --git a/tests/browser/features/support/file_helper.rb 
b/tests/browser/features/support/file_helper.rb
new file mode 100644
index 000..8351b32
--- /dev/null
+++ b/tests/browser/features/support/file_helper.rb
@@ -0,0 +1,23 @@
+require 'tempfile'
+require 'securerandom'
+require 'chunky_png'
+
+module FileHelper
+  def make_temp_image(filename, shade, width, height)
+path = #{Dir.tmpdir}/#{filename}
+image = ChunkyPNG::Image.new(shade, width, height)
+image.save path
+path
+  end
+
+  def create_large_file(size)
+path = Tempfile.new(['temp', '.png']).path
+# making the image consist of many triggers might trigger MediaWiki pixel 
limits
+# instead make it 1x1 and pump it up with metadata
+image = ChunkyPNG::Image.new(1, 1)
+# Chunky will compress long fields so we need to make sure it is 
incomrpessible
+image.metadata['Comment'] = SecureRandom.random_bytes(size)
+   image.save path
+   path
+  end
+end
diff --git a/tests/browser/features/support/pages/upload_wizard_page.rb 
b/tests/browser/features/support/pages/upload_wizard_page.rb
index 1f1832a..d520556 100644
--- a/tests/browser/features/support/pages/upload_wizard_page.rb
+++ b/tests/browser/features/support/pages/upload_wizard_page.rb
@@ -18,6 +18,23 @@
   end
   page_url url
 
+  # if we are on the learn step, move to next step, otherwise do nothing
+  def bypass_learn_step
+   if not stepdiv_file_element.visible?
+  next_element.when_present(15).click
+  wait_for_ajax
+end
+  end
+
+  def enable_chunked_uploads
+# quite a nasty hack. Faster than actually enabling and reloading, though, 
and does not have race conditions
+@browser.execute_script('mw.UploadWizard.config.enableChunked = true;')
+# by default chunked upload triggers for 100+M