Commit efcb54d2 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Settings: Change Picture: Fix update on revisit

Currently re-visiting the change picture page will not
request an image update.

Bug: 730031
Change-Id: I69afb9ef5a51f5d69ae31df2090b2776a39f8ada
Reviewed-on: https://chromium-review.googlesource.com/570817
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487270}
parent 06f34ffd
...@@ -88,6 +88,7 @@ Polymer({ ...@@ -88,6 +88,7 @@ Polymer({
currentRouteChanged: function(newRoute) { currentRouteChanged: function(newRoute) {
if (newRoute == settings.routes.CHANGE_PICTURE) { if (newRoute == settings.routes.CHANGE_PICTURE) {
this.browserProxy_.initialize(); this.browserProxy_.initialize();
this.browserProxy_.requestSelectedImage();
this.pictureList_.setFocus(); this.pictureList_.setFocus();
} else { } else {
// Ensure we deactivate the camera when we navigate away. // Ensure we deactivate the camera when we navigate away.
......
...@@ -61,6 +61,9 @@ cr.define('settings', function() { ...@@ -61,6 +61,9 @@ cr.define('settings', function() {
* expected. * expected.
*/ */
chooseFile() {} chooseFile() {}
/** Requests the currently selected image. */
requestSelectedImage() {}
} }
/** /**
...@@ -96,6 +99,11 @@ cr.define('settings', function() { ...@@ -96,6 +99,11 @@ cr.define('settings', function() {
chooseFile() { chooseFile() {
chrome.send('chooseFile'); chrome.send('chooseFile');
} }
/** @override */
requestSelectedImage() {
chrome.send('requestSelectedImage');
}
} }
// The singleton instance_ is replaced with a test version of this wrapper // The singleton instance_ is replaced with a test version of this wrapper
......
...@@ -114,6 +114,10 @@ void ChangePictureHandler::RegisterMessages() { ...@@ -114,6 +114,10 @@ void ChangePictureHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"selectImage", base::Bind(&ChangePictureHandler::HandleSelectImage, "selectImage", base::Bind(&ChangePictureHandler::HandleSelectImage,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"requestSelectedImage",
base::Bind(&ChangePictureHandler::HandleRequestSelectedImage,
base::Unretained(this)));
} }
void ChangePictureHandler::OnJavascriptAllowed() { void ChangePictureHandler::OnJavascriptAllowed() {
...@@ -322,6 +326,11 @@ void ChangePictureHandler::HandleSelectImage(const base::ListValue* args) { ...@@ -322,6 +326,11 @@ void ChangePictureHandler::HandleSelectImage(const base::ListValue* args) {
ImageDecoder::Cancel(this); ImageDecoder::Cancel(this);
} }
void ChangePictureHandler::HandleRequestSelectedImage(
const base::ListValue* args) {
SendSelectedImage();
}
void ChangePictureHandler::FileSelected(const base::FilePath& path, void ChangePictureHandler::FileSelected(const base::FilePath& path,
int index, int index,
void* params) { void* params) {
......
...@@ -87,6 +87,9 @@ class ChangePictureHandler : public ::settings::SettingsPageUIHandler, ...@@ -87,6 +87,9 @@ class ChangePictureHandler : public ::settings::SettingsPageUIHandler,
// Selects one of the available images as user's. // Selects one of the available images as user's.
void HandleSelectImage(const base::ListValue* args); void HandleSelectImage(const base::ListValue* args);
// Requests the currently selected image.
void HandleRequestSelectedImage(const base::ListValue* args);
// SelectFileDialog::Delegate implementation. // SelectFileDialog::Delegate implementation.
void FileSelected(const base::FilePath& path, void FileSelected(const base::FilePath& path,
int index, int index,
......
...@@ -16,6 +16,7 @@ cr.define('settings_people_page_change_picture', function() { ...@@ -16,6 +16,7 @@ cr.define('settings_people_page_change_picture', function() {
'selectProfileImage', 'selectProfileImage',
'photoTaken', 'photoTaken',
'chooseFile', 'chooseFile',
'requestSelectedImage',
]); ]);
}; };
...@@ -76,6 +77,11 @@ cr.define('settings_people_page_change_picture', function() { ...@@ -76,6 +77,11 @@ cr.define('settings_people_page_change_picture', function() {
chooseFile: function() { chooseFile: function() {
this.methodCalled('chooseFile'); this.methodCalled('chooseFile');
}, },
/** @override */
requestSelectedImage: function() {
this.methodCalled('requestSelectedImage');
},
}; };
function registerChangePictureTests() { function registerChangePictureTests() {
...@@ -187,6 +193,8 @@ cr.define('settings_people_page_change_picture', function() { ...@@ -187,6 +193,8 @@ cr.define('settings_people_page_change_picture', function() {
}); });
test('ChangePictureOldImage', function() { test('ChangePictureOldImage', function() {
assertFalse(!!changePicture.selectedItem_);
// By default there is no old image and the element is hidden. // By default there is no old image and the element is hidden.
var oldImage = crPictureList.$.oldImage; var oldImage = crPictureList.$.oldImage;
assertTrue(!!oldImage); assertTrue(!!oldImage);
...@@ -195,15 +203,20 @@ cr.define('settings_people_page_change_picture', function() { ...@@ -195,15 +203,20 @@ cr.define('settings_people_page_change_picture', function() {
cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg'); cr.webUIListenerCallback('old-image-changed', 'fake-old-image.jpg');
Polymer.dom.flush(); Polymer.dom.flush();
// Expect the old image to be selected once an old image is sent via return new Promise(function(resolve) {
// the native interface. changePicture.async(resolve);
expectEquals(CrPicture.SelectionTypes.OLD, }).then(function() {
changePicture.selectedItem_.dataset.type); assertTrue(!!changePicture.selectedItem_);
expectFalse(oldImage.hidden); // Expect the old image to be selected once an old image is sent via
expectFalse(crPicturePane.cameraActive_); // the native interface.
var discard = crPicturePane.$$('#discard'); expectEquals(CrPicture.SelectionTypes.OLD,
assertTrue(!!discard); changePicture.selectedItem_.dataset.type);
expectFalse(discard.hidden); expectFalse(oldImage.hidden);
expectFalse(crPicturePane.cameraActive_);
var discard = crPicturePane.$$('#discard');
assertTrue(!!discard);
expectFalse(discard.hidden);
});
}); });
test('ChangePictureSelectFirstDefaultImage', function() { test('ChangePictureSelectFirstDefaultImage', function() {
......
...@@ -118,12 +118,14 @@ Polymer({ ...@@ -118,12 +118,14 @@ Polymer({
*/ */
setOldImageUrl(imageUrl) { setOldImageUrl(imageUrl) {
this.oldImageUrl_ = imageUrl; this.oldImageUrl_ = imageUrl;
if (imageUrl) if (imageUrl) {
this.$.selector.select(this.$.selector.indexOf(this.$.oldImage)); this.$.selector.select(this.$.selector.indexOf(this.$.oldImage));
else if (this.cameraSelected_) this.selectedImageUrl_ = imageUrl;
} else if (this.cameraSelected_) {
this.$.selector.select(this.$.selector.indexOf(this.$.cameraImage)); this.$.selector.select(this.$.selector.indexOf(this.$.cameraImage));
else if (this.fallbackImage_) } else if (this.fallbackImage_) {
this.selectImage_(this.fallbackImage_, true /* activate */); this.selectImage_(this.fallbackImage_, true /* activate */);
}
}, },
/** /**
...@@ -135,6 +137,7 @@ Polymer({ ...@@ -135,6 +137,7 @@ Polymer({
if (!this.selectedItem || if (!this.selectedItem ||
this.selectedItem.dataset.type != CrPicture.SelectionTypes.CAMERA) { this.selectedItem.dataset.type != CrPicture.SelectionTypes.CAMERA) {
this.$.selector.select(this.$.selector.indexOf(image)); this.$.selector.select(this.$.selector.indexOf(image));
this.selectedItem = image;
} }
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment