load mobile css/js files in native iOS/andorid apps and not mobile browsers

fixes: CNVS-29413

test plan:
* set up an account with new ui, and upload a 
  custom css/js 
* using something like postman,
  make an api request to a wiki page
* it should include a <link> to that css file
  and a <script> for that js file.

* make the same request from a mobile web browser
  (you can fake your user agent string in safari
  or chrome dev tools to fake this)
* it should not include that css or js file

Change-Id: I07493c8dc474231463cb1f97c0e07f2aad59ed0f
Reviewed-on: https://gerrit.instructure.com/79921
Reviewed-by: Simon Williams <simon@instructure.com>
Tested-by: Jenkins
QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Ryan Shaw 2016-05-17 15:09:28 -06:00
parent 72e2f5bac0
commit 3a7a18bf81
3 changed files with 35 additions and 18 deletions

View File

@ -442,13 +442,13 @@ define([
<div className="Theme__editor-upload-overrides">
<div className="Theme__editor-upload-overrides_header">
{ I18n.t('File(s) will be included when user content is displayed within Canvas iOS or Android apps.') }
{ I18n.t('File(s) will be included when user content is displayed within the Canvas iOS or Android apps, and in third-party apps built on our API.') }
</div>
<div className="Theme__editor-upload-overrides_form">
<ThemeEditorFileUpload
label={I18n.t('Mobile CSS file')}
label={I18n.t('Mobile app CSS file')}
accept=".css"
name="mobile_css_overrides"
currentValue={this.props.brandConfig.mobile_css_overrides}
@ -457,7 +457,7 @@ define([
/>
<ThemeEditorFileUpload
label={I18n.t('Mobile JavaScript file')}
label={I18n.t('Mobile app JavaScript file')}
accept=".js"
name="mobile_js_overrides"
currentValue={this.props.brandConfig.mobile_js_overrides}

View File

@ -508,7 +508,7 @@ module Api
url_helper = Html::UrlProxy.new(self, context, host, protocol)
account = Context.get_account(context) || @domain_root_account
include_mobile = respond_to?(:mobile_device?, true) && mobile_device?
include_mobile = !(respond_to?(:in_app?, true) && in_app?)
Html::Content.rewrite_outgoing(html, account, url_helper, include_mobile: include_mobile)
end

View File

@ -659,22 +659,39 @@ describe Api do
expect(res).to eq html
end
it 'prepends mobile css' do
student_in_course
account = @course.root_account
account.enable_feature!(:use_new_styles)
bc = BrandConfig.create(mobile_css_overrides: 'somewhere.css')
account.brand_config_md5 = bc.md5
account.save!
context "mobile css/js" do
before(:each) do
student_in_course
account = @course.root_account
account.enable_feature!(:use_new_styles)
bc = BrandConfig.create(mobile_css_overrides: 'somewhere.css')
account.brand_config_md5 = bc.md5
account.save!
html = "<p>a</p><p>b</p>"
@html = "<p>a</p><p>b</p>"
k = klass.new
k.stubs(:mobile_device?).returns(true)
res = k.api_user_content(html, @course, @student)
expect(res).to eq <<-HTML.strip
<link rel="stylesheet" href="somewhere.css"><p>a</p><p>b</p>
HTML
@k = klass.new
end
it 'prepends mobile css when not coming from a web browser' do
res = @k.api_user_content(@html, @course, @student)
expect(res).to eq <<-HTML.strip
<link rel="stylesheet" href="somewhere.css"><p>a</p><p>b</p>
HTML
end
it 'does not prepend mobile css when coming from a web browser' do
@k.stubs(:in_app?).returns(true)
res = @k.api_user_content(@html, @course, @student)
expect(res).to eq "<p>a</p><p>b</p>"
end
it 'does not prepend mobile css when coming from a web browser, even if it is a mobile browser' do
@k.stubs(:in_app?).returns(true)
@k.stubs(:mobile_device?).returns(true)
res = @k.api_user_content(@html, @course, @student)
expect(res).to eq "<p>a</p><p>b</p>"
end
end
end